@Test public void testComputeNodeVlanProperties() { int vlan = 1; InterfaceSpecifier interfacesSpecifier = SpecifierFactories.getInterfaceSpecifierOrDefault( null, AllInterfacesInterfaceSpecifier.INSTANCE); IntegerSpace vlans = IntegerSpace.of(vlan); Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder = ImmutableMap.builder(); Interface iface = _ib.build(); iface.setSwitchport(true); iface.setSwitchportMode(SwitchportMode.ACCESS); iface.setAccessVlan(vlan); Configuration c = _configurations.values().iterator().next(); int vni = 10000; c.getDefaultVrf().addLayer2Vni(_vnb.setVlan(vlan).setVni(vni).build()); computeNodeVlanProperties( _specifierContext, c, interfacesSpecifier, false, vlans, switchedVlanInterfaces, vlanVnisBuilder); assertThat(switchedVlanInterfaces, hasKey(vlan)); assertThat( switchedVlanInterfaces.get(vlan).build(), contains(NodeInterfacePair.of(NODE, INTERFACE))); assertThat(vlanVnisBuilder.build(), equalTo(ImmutableMap.of(vlan, vni))); }
@VisibleForTesting static void computeNodeVlanProperties( SpecifierContext ctxt, Configuration c, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder) { addVlanVnis(c, vlans, switchedVlanInterfaces, vlanVnisBuilder); Set<NodeInterfacePair> specifiedInterfaces = interfacesSpecifier.resolve(ImmutableSet.of(c.getHostname()), ctxt); for (Interface iface : c.getAllInterfaces().values()) { tryAddInterfaceToVlans( specifiedInterfaces, excludeShutInterfaces, vlans, switchedVlanInterfaces, iface); } }
SwitchedVlanPropertiesAnswerer extends Answerer { @VisibleForTesting static void computeNodeVlanProperties( SpecifierContext ctxt, Configuration c, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder) { addVlanVnis(c, vlans, switchedVlanInterfaces, vlanVnisBuilder); Set<NodeInterfacePair> specifiedInterfaces = interfacesSpecifier.resolve(ImmutableSet.of(c.getHostname()), ctxt); for (Interface iface : c.getAllInterfaces().values()) { tryAddInterfaceToVlans( specifiedInterfaces, excludeShutInterfaces, vlans, switchedVlanInterfaces, iface); } } }
SwitchedVlanPropertiesAnswerer extends Answerer { @VisibleForTesting static void computeNodeVlanProperties( SpecifierContext ctxt, Configuration c, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder) { addVlanVnis(c, vlans, switchedVlanInterfaces, vlanVnisBuilder); Set<NodeInterfacePair> specifiedInterfaces = interfacesSpecifier.resolve(ImmutableSet.of(c.getHostname()), ctxt); for (Interface iface : c.getAllInterfaces().values()) { tryAddInterfaceToVlans( specifiedInterfaces, excludeShutInterfaces, vlans, switchedVlanInterfaces, iface); } } SwitchedVlanPropertiesAnswerer(Question question, IBatfish batfish); }
SwitchedVlanPropertiesAnswerer extends Answerer { @VisibleForTesting static void computeNodeVlanProperties( SpecifierContext ctxt, Configuration c, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder) { addVlanVnis(c, vlans, switchedVlanInterfaces, vlanVnisBuilder); Set<NodeInterfacePair> specifiedInterfaces = interfacesSpecifier.resolve(ImmutableSet.of(c.getHostname()), ctxt); for (Interface iface : c.getAllInterfaces().values()) { tryAddInterfaceToVlans( specifiedInterfaces, excludeShutInterfaces, vlans, switchedVlanInterfaces, iface); } } SwitchedVlanPropertiesAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(); static String getColumnName(String property); static Multiset<Row> getProperties(
      SpecifierContext ctxt,
      Map<String, Configuration> configurations,
      Set<String> nodes,
      InterfaceSpecifier interfaceSpecifier,
      boolean excludeShutInterfaces,
      IntegerSpace vlans,
      Map<String, ColumnMetadata> columns); @Override TableAnswerElement answer(NetworkSnapshot snapshot); }
SwitchedVlanPropertiesAnswerer extends Answerer { @VisibleForTesting static void computeNodeVlanProperties( SpecifierContext ctxt, Configuration c, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder) { addVlanVnis(c, vlans, switchedVlanInterfaces, vlanVnisBuilder); Set<NodeInterfacePair> specifiedInterfaces = interfacesSpecifier.resolve(ImmutableSet.of(c.getHostname()), ctxt); for (Interface iface : c.getAllInterfaces().values()) { tryAddInterfaceToVlans( specifiedInterfaces, excludeShutInterfaces, vlans, switchedVlanInterfaces, iface); } } SwitchedVlanPropertiesAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(); static String getColumnName(String property); static Multiset<Row> getProperties(
      SpecifierContext ctxt,
      Map<String, Configuration> configurations,
      Set<String> nodes,
      InterfaceSpecifier interfaceSpecifier,
      boolean excludeShutInterfaces,
      IntegerSpace vlans,
      Map<String, ColumnMetadata> columns); @Override TableAnswerElement answer(NetworkSnapshot snapshot);  }