use of org.batfish.datamodel.CommunityList in project batfish by batfish.
the class TransferBDD method matchCommunitySet.
/*
* Converts a community set to a boolean expression
*/
private BDD matchCommunitySet(TransferParam<BDDRoute> p, Configuration conf, CommunitySetExpr e, BDDRoute other) {
if (e instanceof InlineCommunitySet) {
Set<CommunityVar> comms = _graph.findAllCommunities(conf, e);
BDD acc = factory.one();
for (CommunityVar comm : comms) {
p.debug("Inline Community Set: " + comm);
BDD c = other.getCommunities().get(comm);
if (c == null) {
throw new BatfishException("matchCommunitySet: should not be null");
}
acc = acc.and(c);
}
return acc;
}
if (e instanceof NamedCommunitySet) {
p.debug("Named");
NamedCommunitySet x = (NamedCommunitySet) e;
CommunityList cl = conf.getCommunityLists().get(x.getName());
p.debug("Named Community Set: " + cl.getName());
return matchCommunityList(p, cl, other);
}
throw new BatfishException("TODO: match community set");
}
use of org.batfish.datamodel.CommunityList in project batfish by batfish.
the class NamedCommunitySet method allCommunities.
@Override
public SortedSet<Long> allCommunities(Environment environment) {
ImmutableSortedSet.Builder<Long> out = ImmutableSortedSet.naturalOrder();
CommunityList cl = environment.getConfiguration().getCommunityLists().get(_name);
for (CommunityListLine line : cl.getLines()) {
Long community = line.toLiteralCommunity();
out.add(community);
}
return out.build();
}
use of org.batfish.datamodel.CommunityList in project batfish by batfish.
the class CiscoGrammarTest method testCommunityListConversion.
@Test
public void testCommunityListConversion() throws IOException {
String testrigName = "community-list-conversion";
String iosName = "ios";
String nxosName = "nxos";
String eosName = "eos";
List<String> configurationNames = ImmutableList.of(iosName, nxosName, eosName);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Map<String, Configuration> configurations = batfish.loadConfigurations();
Configuration iosCommunityListConfig = configurations.get(iosName);
SortedMap<String, CommunityList> iosCommunityLists = iosCommunityListConfig.getCommunityLists();
Configuration eosCommunityListConfig = configurations.get(eosName);
SortedMap<String, CommunityList> eosCommunityLists = eosCommunityListConfig.getCommunityLists();
Configuration nxosCommunityListConfig = configurations.get(nxosName);
SortedMap<String, CommunityList> nxosCommunityLists = nxosCommunityListConfig.getCommunityLists();
String iosRegexImpliedStd = getCLRegex(iosCommunityLists, "40");
String iosRegexImpliedExp = getCLRegex(iosCommunityLists, "400");
String iosRegexStd = getCLRegex(iosCommunityLists, "std_community");
String iosRegexExp = getCLRegex(iosCommunityLists, "exp_community");
String iosRegexStdAsnn = getCLRegex(iosCommunityLists, "std_as_nn");
String iosRegexExpAsnn = getCLRegex(iosCommunityLists, "exp_as_nn");
String iosRegexStdGshut = getCLRegex(iosCommunityLists, "std_gshut");
String iosRegexExpGshut = getCLRegex(iosCommunityLists, "exp_gshut");
String iosRegexStdInternet = getCLRegex(iosCommunityLists, "std_internet");
String iosRegexExpInternet = getCLRegex(iosCommunityLists, "exp_internet");
String iosRegexStdLocalAs = getCLRegex(iosCommunityLists, "std_local_AS");
String iosRegexExpLocalAs = getCLRegex(iosCommunityLists, "exp_local_AS");
String iosRegexStdNoAdv = getCLRegex(iosCommunityLists, "std_no_advertise");
String iosRegexExpNoAdv = getCLRegex(iosCommunityLists, "exp_no_advertise");
String iosRegexStdNoExport = getCLRegex(iosCommunityLists, "std_no_export");
String iosRegexExpNoExport = getCLRegex(iosCommunityLists, "exp_no_export");
String eosRegexStd = getCLRegex(eosCommunityLists, "eos_std");
String eosRegexExp = getCLRegex(eosCommunityLists, "eos_exp");
String eosRegexStdGshut = getCLRegex(eosCommunityLists, "eos_std_gshut");
String eosRegexStdInternet = getCLRegex(eosCommunityLists, "eos_std_internet");
String eosRegexStdLocalAs = getCLRegex(eosCommunityLists, "eos_std_local_AS");
String eosRegexStdNoAdv = getCLRegex(eosCommunityLists, "eos_std_no_adv");
String eosRegexStdNoExport = getCLRegex(eosCommunityLists, "eos_std_no_export");
String eosRegexStdMulti = getCLRegex(eosCommunityLists, "eos_std_multi");
String eosRegexExpMulti = getCLRegex(eosCommunityLists, "eos_exp_multi");
String nxosRegexStd = getCLRegex(nxosCommunityLists, "nxos_std");
String nxosRegexExp = getCLRegex(nxosCommunityLists, "nxos_exp");
String nxosRegexStdInternet = getCLRegex(nxosCommunityLists, "nxos_std_internet");
String nxosRegexStdLocalAs = getCLRegex(nxosCommunityLists, "nxos_std_local_AS");
String nxosRegexStdNoAdv = getCLRegex(nxosCommunityLists, "nxos_std_no_adv");
String nxosRegexStdNoExport = getCLRegex(nxosCommunityLists, "nxos_std_no_export");
String nxosRegexStdMulti = getCLRegex(nxosCommunityLists, "nxos_std_multi");
String nxosRegexExpMulti = getCLRegex(nxosCommunityLists, "nxos_exp_multi");
// Check well known community regexes are generated properly
String regexInternet = "^" + CommonUtil.longToCommunity(WellKnownCommunity.INTERNET.getValue()) + "$";
String regexNoAdv = "^" + CommonUtil.longToCommunity(WellKnownCommunity.NO_ADVERTISE.getValue()) + "$";
String regexNoExport = "^" + CommonUtil.longToCommunity(WellKnownCommunity.NO_EXPORT.getValue()) + "$";
String regexGshut = "^" + CommonUtil.longToCommunity(WellKnownCommunity.GSHUT.getValue()) + "$";
String regexLocalAs = "^" + CommonUtil.longToCommunity(WellKnownCommunity.LOCAL_AS.getValue()) + "$";
assertThat(iosRegexStdInternet, equalTo(regexInternet));
assertThat(iosRegexStdNoAdv, equalTo(regexNoAdv));
assertThat(iosRegexStdNoExport, equalTo(regexNoExport));
assertThat(iosRegexStdGshut, equalTo(regexGshut));
assertThat(iosRegexStdLocalAs, equalTo(regexLocalAs));
assertThat(eosRegexStdInternet, equalTo(regexInternet));
assertThat(eosRegexStdNoAdv, equalTo(regexNoAdv));
assertThat(eosRegexStdNoExport, equalTo(regexNoExport));
assertThat(eosRegexStdGshut, equalTo(regexGshut));
assertThat(eosRegexStdLocalAs, equalTo(regexLocalAs));
// NX-OS does not support gshut
assertThat(nxosRegexStdInternet, equalTo(regexInternet));
assertThat(nxosRegexStdNoAdv, equalTo(regexNoAdv));
assertThat(nxosRegexStdNoExport, equalTo(regexNoExport));
assertThat(nxosRegexStdLocalAs, equalTo(regexLocalAs));
// Confirm for the same literal communities, standard and expanded regexs are different
assertThat(iosRegexImpliedStd, not(equalTo(iosRegexImpliedExp)));
assertThat(iosRegexStd, not(equalTo(iosRegexExp)));
assertThat(iosRegexStdAsnn, not(equalTo(iosRegexExpAsnn)));
assertThat(iosRegexStdInternet, not(equalTo(iosRegexExpInternet)));
assertThat(iosRegexStdNoAdv, not(equalTo(iosRegexExpNoAdv)));
assertThat(iosRegexStdNoExport, not(equalTo(iosRegexExpNoExport)));
assertThat(iosRegexStdGshut, not(equalTo(iosRegexExpGshut)));
assertThat(iosRegexStdLocalAs, not(equalTo(iosRegexExpLocalAs)));
assertThat(eosRegexStd, not(equalTo(eosRegexExp)));
assertThat(eosRegexStdMulti, not(equalTo(eosRegexExpMulti)));
assertThat(nxosRegexStd, not(equalTo(nxosRegexExp)));
assertThat(nxosRegexStdMulti, not(equalTo(nxosRegexExpMulti)));
}
Aggregations