use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VpcTest method cidrBlocks.
@Test
public void cidrBlocks() throws JSONException {
String vpcs = CommonUtil.readResource("org/batfish/representation/aws/VpcTest-multipleCidrBlocks.json");
JSONObject jObj = new JSONObject(vpcs);
JSONArray vpcArray = jObj.getJSONArray("Vpcs");
Vpc vpc = new Vpc(vpcArray.getJSONObject(0), null);
Prefix p1 = Prefix.parse("10.100.0.0/16");
Prefix p2 = Prefix.parse("10.200.0.0/16");
assertThat(vpc.getCidrBlock(), equalTo(p1));
assertThat(vpc.getCidrBlockAssociations(), hasSize(2));
assertThat(vpc.getCidrBlockAssociations(), hasItem(p1));
assertThat(vpc.getCidrBlockAssociations(), hasItem(p2));
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitSummary_address_is_stanza.
// @Override
// public void exitSubnet_bgp_tail(Subnet_bgp_tailContext ctx) {
// BgpProcess proc = currentVrf().getBgpProcess();
// if (ctx.IP_PREFIX() != null) {
// Prefix prefix = new Prefix(ctx.IP_PREFIX().getText());
// NamedBgpPeerGroup namedGroup = _currentNamedPeerGroup;
// namedGroup.addNeighborIpPrefix(prefix);
// DynamicIpBgpPeerGroup pg = proc.addDynamicIpPeerGroup(prefix);
// pg.setGroupName(namedGroup.getName());
// }
// else if (ctx.IPV6_PREFIX() != null) {
// Prefix6 prefix6 = new Prefix6(ctx.IPV6_PREFIX().getText());
// NamedBgpPeerGroup namedGroup = _currentNamedPeerGroup;
// namedGroup.addNeighborIpv6Prefix(prefix6);
// DynamicIpv6BgpPeerGroup pg = proc.addDynamicIpv6PeerGroup(prefix6);
// pg.setGroupName(namedGroup.getName());
// }
// }
//
@Override
public void exitSummary_address_is_stanza(Summary_address_is_stanzaContext ctx) {
Ip ip = toIp(ctx.ip);
Ip mask = toIp(ctx.mask);
Prefix prefix = new Prefix(ip, mask);
RoutingProtocol sourceProtocol = RoutingProtocol.ISIS_L1;
IsisRedistributionPolicy r = new IsisRedistributionPolicy(sourceProtocol);
r.setSummaryPrefix(prefix);
_currentIsisProcess.getRedistributionPolicies().put(sourceProtocol, r);
if (ctx.metric != null) {
int metric = toInteger(ctx.metric);
r.setMetric(metric);
}
if (!ctx.LEVEL_1().isEmpty()) {
r.setLevel(IsisLevel.LEVEL_1);
} else if (!ctx.LEVEL_2().isEmpty()) {
r.setLevel(IsisLevel.LEVEL_2);
} else if (!ctx.LEVEL_1_2().isEmpty()) {
r.setLevel(IsisLevel.LEVEL_1_2);
} else {
r.setLevel(IsisRedistributionPolicy.DEFAULT_LEVEL);
}
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitRo_area_range.
@Override
public void exitRo_area_range(CiscoParser.Ro_area_rangeContext ctx) {
long areaNum = (ctx.area_int != null) ? toLong(ctx.area_int) : toIp(ctx.area_ip).asLong();
Prefix prefix;
if (ctx.area_prefix != null) {
prefix = Prefix.parse(ctx.area_prefix.getText());
} else {
prefix = new Prefix(new Ip(ctx.area_ip.getText()), new Ip(ctx.area_subnet.getText()));
}
boolean advertise = ctx.NOT_ADVERTISE() == null;
Long cost = ctx.cost == null ? null : toLong(ctx.cost);
Map<Prefix, OspfAreaSummary> area = currentVrf().getOspfProcess().getSummaries().computeIfAbsent(areaNum, k -> new TreeMap<>());
area.put(prefix, new OspfAreaSummary(advertise, cost));
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitIp_route_tail.
@Override
public void exitIp_route_tail(Ip_route_tailContext ctx) {
Prefix prefix;
if (ctx.prefix != null) {
prefix = Prefix.parse(ctx.prefix.getText());
} else {
Ip address = toIp(ctx.address);
Ip mask = toIp(ctx.mask);
int prefixLength = mask.numSubnetBits();
prefix = new Prefix(address, prefixLength);
}
Ip nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
String nextHopInterface = null;
int distance = DEFAULT_STATIC_ROUTE_DISTANCE;
Integer tag = null;
Integer track = null;
boolean permanent = ctx.perm != null;
if (ctx.nexthopip != null) {
nextHopIp = toIp(ctx.nexthopip);
} else if (ctx.nexthopprefix != null) {
Prefix nextHopPrefix = Prefix.parse(ctx.nexthopprefix.getText());
nextHopIp = nextHopPrefix.getStartIp();
}
if (ctx.nexthopint != null) {
try {
nextHopInterface = getCanonicalInterfaceName(ctx.nexthopint.getText());
} catch (BatfishException e) {
_w.redFlag("Error fetching interface name at: " + getLocation(ctx) + getFullText(ctx) + " : " + e.getMessage());
_currentInterfaces = ImmutableList.of();
return;
}
}
if (ctx.distance != null) {
distance = toInteger(ctx.distance);
}
if (ctx.tag != null) {
tag = toInteger(ctx.tag);
}
if (ctx.track != null) {
track = toInteger(ctx.track);
}
StaticRoute route = new StaticRoute(prefix, nextHopIp, nextHopInterface, distance, tag, track, permanent);
currentVrf().getStaticRoutes().add(route);
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class CiscoControlPlaneExtractor method enterNeighbor_block_rb_stanza.
@Override
public void enterNeighbor_block_rb_stanza(Neighbor_block_rb_stanzaContext ctx) {
_currentBlockNeighborAddressFamilies.clear();
_inBlockNeighbor = true;
// do no further processing for unsupported address families / containers
if (_currentPeerGroup == _dummyPeerGroup) {
pushPeer(_dummyPeerGroup);
return;
}
BgpProcess proc = currentVrf().getBgpProcess();
if (ctx.ip_address != null) {
Ip ip = toIp(ctx.ip_address);
_currentIpPeerGroup = proc.getIpPeerGroups().get(ip);
if (_currentIpPeerGroup == null) {
proc.addIpPeerGroup(ip);
_currentIpPeerGroup = proc.getIpPeerGroups().get(ip);
} else {
_w.redFlag("Duplicate IP peer group in neighbor config (line:" + ctx.start.getLine() + ")", DUPLICATE);
}
pushPeer(_currentIpPeerGroup);
} else if (ctx.ip_prefix != null) {
Prefix prefix = Prefix.parse(ctx.ip_prefix.getText());
_currentDynamicIpPeerGroup = proc.getDynamicIpPeerGroups().get(prefix);
if (_currentDynamicIpPeerGroup == null) {
_currentDynamicIpPeerGroup = proc.addDynamicIpPeerGroup(prefix);
} else {
_w.redFlag("Duplicate DynamicIP peer group neighbor config (line:" + ctx.start.getLine() + ")", DUPLICATE);
}
pushPeer(_currentDynamicIpPeerGroup);
} else if (ctx.ipv6_address != null) {
Ip6 ip6 = toIp6(ctx.ipv6_address);
Ipv6BgpPeerGroup pg = proc.getIpv6PeerGroups().get(ip6);
if (pg == null) {
proc.addIpv6PeerGroup(ip6);
pg = proc.getIpv6PeerGroups().get(ip6);
} else {
_w.redFlag("Duplicate IPV6 peer group in neighbor config (line:" + ctx.start.getLine() + ")", DUPLICATE);
}
pushPeer(pg);
_currentIpv6PeerGroup = pg;
} else if (ctx.ipv6_prefix != null) {
Prefix6 prefix6 = new Prefix6(ctx.ipv6_prefix.getText());
DynamicIpv6BgpPeerGroup pg = proc.getDynamicIpv6PeerGroups().get(prefix6);
if (pg == null) {
pg = proc.addDynamicIpv6PeerGroup(prefix6);
} else {
_w.redFlag("Duplicate Dynamic Ipv6 peer group neighbor config (line:" + ctx.start.getLine() + ")", DUPLICATE);
}
pushPeer(pg);
_currentDynamicIpv6PeerGroup = pg;
}
if (ctx.REMOTE_AS() != null) {
int remoteAs = toInteger(ctx.asnum);
_currentPeerGroup.setRemoteAs(remoteAs);
}
// TODO: verify if this is correct for nexus
_currentPeerGroup.setActive(true);
_currentPeerGroup.setShutdown(false);
}
Aggregations