use of org.batfish.datamodel.BgpAdvertisement in project batfish by batfish.
the class BdpDataPlanePlugin method computeDataPlane.
@Override
public ComputeDataPlaneResult computeDataPlane(boolean differentialContext, Map<String, Configuration> configurations, Topology topology) {
BdpAnswerElement ae = new BdpAnswerElement();
Set<BgpAdvertisement> externalAdverts = _batfish.loadExternalBgpAnnouncements(configurations);
BdpDataPlane dp = _engine.computeDataPlane(differentialContext, configurations, topology, externalAdverts, ae);
double averageRoutes = dp.getNodes().values().stream().flatMap(n -> n._virtualRouters.values().stream()).mapToInt(vr -> vr._mainRib.getRoutes().size()).average().orElse(0.00d);
_logger.infof("Generated data plane for testrig:%s in container:%s; iterations:%s, total nodes:%s, " + "avg entries per node:%.2f, work-id:%s\n", _batfish.getTestrigName(), _batfish.getContainerName(), ae.getDependentRoutesIterations(), configurations.size(), averageRoutes, _batfish.getTaskId());
return new ComputeDataPlaneResult(ae, dp);
}
use of org.batfish.datamodel.BgpAdvertisement in project batfish by batfish.
the class Batfish method loadExternalBgpAnnouncements.
@Override
public Set<BgpAdvertisement> loadExternalBgpAnnouncements(Map<String, Configuration> configurations) {
Set<BgpAdvertisement> advertSet = new LinkedHashSet<>();
for (ExternalBgpAdvertisementPlugin plugin : _externalBgpAdvertisementPlugins) {
Set<BgpAdvertisement> currentAdvertisements = plugin.loadExternalBgpAdvertisements();
advertSet.addAll(currentAdvertisements);
}
return advertSet;
}
use of org.batfish.datamodel.BgpAdvertisement in project batfish by batfish.
the class Batfish method processExternalBgpAnnouncements.
/**
* Reads the external bgp announcement specified in the environment, and populates the
* vendor-independent configurations with data about those announcements
*
* @param configurations The vendor-independent configurations to be modified
*/
public Set<BgpAdvertisement> processExternalBgpAnnouncements(Map<String, Configuration> configurations, SortedSet<Long> allCommunities) {
Set<BgpAdvertisement> advertSet = new LinkedHashSet<>();
Path externalBgpAnnouncementsPath = _testrigSettings.getEnvironmentSettings().getExternalBgpAnnouncementsPath();
if (Files.exists(externalBgpAnnouncementsPath)) {
String externalBgpAnnouncementsFileContents = CommonUtil.readFile(externalBgpAnnouncementsPath);
try {
JSONObject jsonObj = new JSONObject(externalBgpAnnouncementsFileContents);
JSONArray announcements = jsonObj.getJSONArray(BfConsts.PROP_BGP_ANNOUNCEMENTS);
for (int index = 0; index < announcements.length(); index++) {
JSONObject announcement = new JSONObject();
announcement.put("@id", index);
JSONObject announcementSrc = announcements.getJSONObject(index);
for (Iterator<?> i = announcementSrc.keys(); i.hasNext(); ) {
String key = (String) i.next();
if (!key.equals("@id")) {
announcement.put(key, announcementSrc.get(key));
}
}
BgpAdvertisement bgpAdvertisement = BatfishObjectMapper.mapper().readValue(announcement.toString(), BgpAdvertisement.class);
allCommunities.addAll(bgpAdvertisement.getCommunities());
advertSet.add(bgpAdvertisement);
}
} catch (JSONException | IOException e) {
throw new BatfishException("Problems parsing JSON in " + externalBgpAnnouncementsPath, e);
}
}
return advertSet;
}
use of org.batfish.datamodel.BgpAdvertisement in project batfish by batfish.
the class CounterExample method buildFlowHistory.
/*
* Creates a trace-based example of what happens
* to a packet (e.g., why it is not reachable).
*/
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
FlowHistory fh = new FlowHistory();
for (String source : sourceRouters) {
Boolean sourceVar = reach.get(source);
if (!sourceVar) {
Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
SortedSet<Edge> failedLinks = buildFailedLinks(enc);
SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
}
}
return fh;
}
use of org.batfish.datamodel.BgpAdvertisement in project batfish by batfish.
the class VirtualRouterTest method computeBgpAdvertisementsSentToOutsideIgp.
@Test
public void computeBgpAdvertisementsSentToOutsideIgp() {
RoutingPolicy exportPolicy = _routingPolicyBuilder.setStatements(ImmutableList.of(new SetOrigin(new LiteralOrigin(OriginType.INCOMPLETE, null)), _exitAcceptStatement)).build();
_bgpNeighborBuilder.setExportPolicy(exportPolicy.getName()).setRemoteAs(TEST_AS2).build();
_testVirtualRouter._mainRib.mergeRoute(new OspfInternalRoute.Builder().setNetwork(TEST_NETWORK).setMetric(TEST_METRIC).setArea(TEST_AREA).setAdmin(TEST_ADMIN).setProtocol(RoutingProtocol.OSPF).build());
// checking number of bgp advertisements
assertThat(_testVirtualRouter.computeBgpAdvertisementsToOutside(_ipOwners), equalTo(1));
BgpAdvertisement bgpAdvertisement = _testVirtualRouter._sentBgpAdvertisements.iterator().next();
// checking the attributes of the bgp advertisement
assertThat(bgpAdvertisement, hasDestinationIp(TEST_DEST_IP));
assertThat(bgpAdvertisement, hasNetwork(TEST_NETWORK));
assertThat(bgpAdvertisement, hasOriginatorIp(TEST_SRC_IP));
assertThat(bgpAdvertisement, hasType(BgpAdvertisementType.EBGP_SENT));
assertThat(bgpAdvertisement, hasSourceIp(TEST_SRC_IP));
}
Aggregations