@Test public void getProperties() { BgpProcess bgp1 = new BgpProcess(Ip.parse("1.1.1.1"), ConfigurationFormat.CISCO_IOS); bgp1.setMultipathEbgp(true); bgp1.setTieBreaker(BgpTieBreaker.ARRIVAL_ORDER); Vrf vrf1 = new Vrf("vrf1"); vrf1.setBgpProcess(bgp1); Configuration conf1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); conf1.setVrfs(ImmutableMap.of("vrf1", vrf1)); String property1 = BgpProcessPropertySpecifier.MULTIPATH_EBGP; String property2 = BgpProcessPropertySpecifier.TIE_BREAKER; BgpProcessConfigurationQuestion question = new BgpProcessConfigurationQuestion( AllNodesNodeSpecifier.INSTANCE, new BgpProcessPropertySpecifier(ImmutableSet.of(property1, property2))); TableMetadata metadata = BgpProcessConfigurationAnswerer.createTableMetadata(question); Multiset<Row> propertyRows = BgpProcessConfigurationAnswerer.getProperties( question.getPropertySpecifier(), MockSpecifierContext.builder().setConfigs(ImmutableMap.of("node1", conf1)).build(), new NameNodeSpecifier("node1"), metadata.toColumnMap()); Row expectedRow = Row.builder() .put(BgpProcessConfigurationAnswerer.COL_NODE, new Node("node1")) .put(BgpProcessConfigurationAnswerer.COL_VRF, "vrf1") .put(BgpProcessConfigurationAnswerer.COL_ROUTER_ID, Ip.parse("1.1.1.1")) .put(property2, BgpTieBreaker.ARRIVAL_ORDER.toString()) .put(property1, true) .build(); assertThat(propertyRows, equalTo(ImmutableMultiset.of(expectedRow))); }
public static Multiset<Row> getProperties( BgpProcessPropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodeSpecifier .resolve(ctxt) .forEach( nodeName -> { ctxt.getConfigs() .get(nodeName) .getVrfs() .values() .forEach( vrf -> { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { return; } RowBuilder rowBuilder = Row.builder(columnMetadata) .put(COL_NODE, new Node(nodeName)) .put(COL_VRF, vrf.getName()) .put(COL_ROUTER_ID, bgpProcess.getRouterId()); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<BgpProcess> propertyDescriptor = BgpProcessPropertySpecifier.getPropertyDescriptor(property); try { PropertySpecifier.fillProperty( propertyDescriptor, bgpProcess, property, rowBuilder); } catch (ClassCastException e) { throw new BatfishException( String.format( "Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName, vrf.getName(), bgpProcess, e.getMessage()), e); } } rows.add(rowBuilder.build()); }); }); return rows; }
BgpProcessConfigurationAnswerer extends Answerer { public static Multiset<Row> getProperties( BgpProcessPropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodeSpecifier .resolve(ctxt) .forEach( nodeName -> { ctxt.getConfigs() .get(nodeName) .getVrfs() .values() .forEach( vrf -> { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { return; } RowBuilder rowBuilder = Row.builder(columnMetadata) .put(COL_NODE, new Node(nodeName)) .put(COL_VRF, vrf.getName()) .put(COL_ROUTER_ID, bgpProcess.getRouterId()); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<BgpProcess> propertyDescriptor = BgpProcessPropertySpecifier.getPropertyDescriptor(property); try { PropertySpecifier.fillProperty( propertyDescriptor, bgpProcess, property, rowBuilder); } catch (ClassCastException e) { throw new BatfishException( String.format( "Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName, vrf.getName(), bgpProcess, e.getMessage()), e); } } rows.add(rowBuilder.build()); }); }); return rows; } }
BgpProcessConfigurationAnswerer extends Answerer { public static Multiset<Row> getProperties( BgpProcessPropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodeSpecifier .resolve(ctxt) .forEach( nodeName -> { ctxt.getConfigs() .get(nodeName) .getVrfs() .values() .forEach( vrf -> { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { return; } RowBuilder rowBuilder = Row.builder(columnMetadata) .put(COL_NODE, new Node(nodeName)) .put(COL_VRF, vrf.getName()) .put(COL_ROUTER_ID, bgpProcess.getRouterId()); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<BgpProcess> propertyDescriptor = BgpProcessPropertySpecifier.getPropertyDescriptor(property); try { PropertySpecifier.fillProperty( propertyDescriptor, bgpProcess, property, rowBuilder); } catch (ClassCastException e) { throw new BatfishException( String.format( "Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName, vrf.getName(), bgpProcess, e.getMessage()), e); } } rows.add(rowBuilder.build()); }); }); return rows; } BgpProcessConfigurationAnswerer(Question question, IBatfish batfish); }
BgpProcessConfigurationAnswerer extends Answerer { public static Multiset<Row> getProperties( BgpProcessPropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodeSpecifier .resolve(ctxt) .forEach( nodeName -> { ctxt.getConfigs() .get(nodeName) .getVrfs() .values() .forEach( vrf -> { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { return; } RowBuilder rowBuilder = Row.builder(columnMetadata) .put(COL_NODE, new Node(nodeName)) .put(COL_VRF, vrf.getName()) .put(COL_ROUTER_ID, bgpProcess.getRouterId()); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<BgpProcess> propertyDescriptor = BgpProcessPropertySpecifier.getPropertyDescriptor(property); try { PropertySpecifier.fillProperty( propertyDescriptor, bgpProcess, property, rowBuilder); } catch (ClassCastException e) { throw new BatfishException( String.format( "Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName, vrf.getName(), bgpProcess, e.getMessage()), e); } } rows.add(rowBuilder.build()); }); }); return rows; } BgpProcessConfigurationAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(
      BgpProcessPropertySpecifier propertySpecifier); @Override AnswerElement answer(NetworkSnapshot snapshot); static String getColumnName(String property); static Multiset<Row> getProperties(
      BgpProcessPropertySpecifier propertySpecifier,
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columnMetadata); }
BgpProcessConfigurationAnswerer extends Answerer { public static Multiset<Row> getProperties( BgpProcessPropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodeSpecifier .resolve(ctxt) .forEach( nodeName -> { ctxt.getConfigs() .get(nodeName) .getVrfs() .values() .forEach( vrf -> { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { return; } RowBuilder rowBuilder = Row.builder(columnMetadata) .put(COL_NODE, new Node(nodeName)) .put(COL_VRF, vrf.getName()) .put(COL_ROUTER_ID, bgpProcess.getRouterId()); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<BgpProcess> propertyDescriptor = BgpProcessPropertySpecifier.getPropertyDescriptor(property); try { PropertySpecifier.fillProperty( propertyDescriptor, bgpProcess, property, rowBuilder); } catch (ClassCastException e) { throw new BatfishException( String.format( "Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName, vrf.getName(), bgpProcess, e.getMessage()), e); } } rows.add(rowBuilder.build()); }); }); return rows; } BgpProcessConfigurationAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(
      BgpProcessPropertySpecifier propertySpecifier); @Override AnswerElement answer(NetworkSnapshot snapshot); static String getColumnName(String property); static Multiset<Row> getProperties(
      BgpProcessPropertySpecifier propertySpecifier,
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columnMetadata); static final String COL_NODE; static final String COL_VRF; static final String COL_ROUTER_ID; }