use of org.batfish.datamodel.Ip6 in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitExtended_ipv6_access_list_tail.
@Override
public void exitExtended_ipv6_access_list_tail(Extended_ipv6_access_list_tailContext ctx) {
LineAction action = toLineAction(ctx.ala);
IpProtocol protocol = toIpProtocol(ctx.prot);
Ip6 srcIp = getIp(ctx.srcipr);
Ip6 srcWildcard = getWildcard(ctx.srcipr);
Ip6 dstIp = getIp(ctx.dstipr);
Ip6 dstWildcard = getWildcard(ctx.dstipr);
String srcAddressGroup = getAddressGroup(ctx.srcipr);
String dstAddressGroup = getAddressGroup(ctx.dstipr);
List<SubRange> srcPortRanges = ctx.alps_src != null ? toPortRanges(ctx.alps_src) : Collections.<SubRange>emptyList();
List<SubRange> dstPortRanges = ctx.alps_dst != null ? toPortRanges(ctx.alps_dst) : Collections.<SubRange>emptyList();
Integer icmpType = null;
Integer icmpCode = null;
List<TcpFlags> tcpFlags = new ArrayList<>();
Set<Integer> dscps = new TreeSet<>();
Set<Integer> ecns = new TreeSet<>();
Set<State> states = EnumSet.noneOf(State.class);
for (Extended_access_list_additional_featureContext feature : ctx.features) {
if (feature.ACK() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseAck(true);
alt.setAck(true);
tcpFlags.add(alt);
}
if (feature.DSCP() != null) {
int dscpType = toDscpType(feature.dscp_type());
dscps.add(dscpType);
}
if (feature.ECE() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseEce(true);
alt.setEce(true);
tcpFlags.add(alt);
}
if (feature.ECHO_REPLY() != null) {
icmpType = IcmpType.ECHO_REPLY;
icmpCode = IcmpCode.ECHO_REPLY;
}
if (feature.ECHO() != null) {
icmpType = IcmpType.ECHO_REQUEST;
icmpCode = IcmpCode.ECHO_REQUEST;
}
if (feature.ECN() != null) {
int ecn = toInteger(feature.ecn);
ecns.add(ecn);
}
if (feature.ESTABLISHED() != null) {
// must contain ACK or RST
TcpFlags alt1 = new TcpFlags();
TcpFlags alt2 = new TcpFlags();
alt1.setUseAck(true);
alt1.setAck(true);
alt2.setUseRst(true);
alt2.setRst(true);
tcpFlags.add(alt1);
tcpFlags.add(alt2);
}
if (feature.FIN() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseFin(true);
alt.setFin(true);
tcpFlags.add(alt);
}
if (feature.FRAGMENTS() != null) {
todo(ctx, F_FRAGMENTS);
}
if (feature.HOST_UNKNOWN() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.DESTINATION_HOST_UNKNOWN;
}
if (feature.HOST_UNREACHABLE() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.DESTINATION_HOST_UNREACHABLE;
}
if (feature.NETWORK_UNKNOWN() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.DESTINATION_NETWORK_UNKNOWN;
}
if (feature.NET_UNREACHABLE() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.DESTINATION_NETWORK_UNREACHABLE;
}
if (feature.PACKET_TOO_BIG() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.PACKET_TOO_BIG;
}
if (feature.PARAMETER_PROBLEM() != null) {
icmpType = IcmpType.PARAMETER_PROBLEM;
}
if (feature.PORT_UNREACHABLE() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
icmpCode = IcmpCode.DESTINATION_PORT_UNREACHABLE;
}
if (feature.PSH() != null) {
TcpFlags alt = new TcpFlags();
alt.setUsePsh(true);
alt.setPsh(true);
tcpFlags.add(alt);
}
if (feature.REDIRECT() != null) {
icmpType = IcmpType.REDIRECT_MESSAGE;
}
if (feature.RST() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseRst(true);
alt.setRst(true);
tcpFlags.add(alt);
}
if (feature.SOURCE_QUENCH() != null) {
icmpType = IcmpType.SOURCE_QUENCH;
icmpCode = IcmpCode.SOURCE_QUENCH;
}
if (feature.SYN() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseSyn(true);
alt.setSyn(true);
tcpFlags.add(alt);
}
if (feature.TIME_EXCEEDED() != null) {
icmpType = IcmpType.TIME_EXCEEDED;
}
if (feature.TTL() != null) {
todo(ctx, F_TTL);
}
if (feature.TTL_EXCEEDED() != null) {
icmpType = IcmpType.TIME_EXCEEDED;
icmpCode = IcmpCode.TTL_EXCEEDED;
}
if (feature.TRACEROUTE() != null) {
icmpType = IcmpType.TRACEROUTE;
icmpCode = IcmpCode.TRACEROUTE;
}
if (feature.TRACKED() != null) {
states.add(State.ESTABLISHED);
}
if (feature.UNREACHABLE() != null) {
icmpType = IcmpType.DESTINATION_UNREACHABLE;
}
if (feature.URG() != null) {
TcpFlags alt = new TcpFlags();
alt.setUseUrg(true);
alt.setUrg(true);
tcpFlags.add(alt);
}
}
String name = getFullText(ctx).trim();
ExtendedIpv6AccessListLine line = new ExtendedIpv6AccessListLine(name, action, protocol, new Ip6Wildcard(srcIp, srcWildcard), srcAddressGroup, new Ip6Wildcard(dstIp, dstWildcard), dstAddressGroup, srcPortRanges, dstPortRanges, dscps, ecns, icmpType, icmpCode, states, tcpFlags);
_currentExtendedIpv6Acl.addLine(line);
}
use of org.batfish.datamodel.Ip6 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);
}
use of org.batfish.datamodel.Ip6 in project batfish by batfish.
the class CiscoControlPlaneExtractor method enterNeighbor_flat_rb_stanza.
@Override
public void enterNeighbor_flat_rb_stanza(Neighbor_flat_rb_stanzaContext ctx) {
// do no further processing for unsupported address families / containers
if (_currentPeerGroup == _dummyPeerGroup) {
pushPeer(_dummyPeerGroup);
return;
}
BgpProcess proc = currentVrf().getBgpProcess();
// we must create peer group if it does not exist and this is a remote_as
// declaration
boolean create = ctx.remote_as_bgp_tail() != null || ctx.inherit_peer_session_bgp_tail() != null;
if (ctx.ip != null) {
Ip ip = toIp(ctx.ip);
_currentIpPeerGroup = proc.getIpPeerGroups().get(ip);
if (_currentIpPeerGroup == null) {
if (create) {
proc.addIpPeerGroup(ip);
_currentIpPeerGroup = proc.getIpPeerGroups().get(ip);
pushPeer(_currentIpPeerGroup);
} else {
String message = "Ignoring reference to undeclared peer group: '" + ip + "'";
_w.redFlag(message);
pushPeer(_dummyPeerGroup);
}
} else {
pushPeer(_currentIpPeerGroup);
}
} else if (ctx.ip6 != null) {
Ip6 ip6 = toIp6(ctx.ip6);
Ipv6BgpPeerGroup pg6 = proc.getIpv6PeerGroups().get(ip6);
if (pg6 == null) {
if (create) {
proc.addIpv6PeerGroup(ip6);
pg6 = proc.getIpv6PeerGroups().get(ip6);
pushPeer(pg6);
} else {
String message = "Ignoring reference to undeclared peer group: '" + ip6 + "'";
_w.redFlag(message);
pushPeer(_dummyPeerGroup);
}
} else {
pushPeer(pg6);
}
_currentIpv6PeerGroup = pg6;
} else if (ctx.peergroup != null) {
String name = ctx.peergroup.getText();
int definitionLine = ctx.peergroup.getLine();
_currentNamedPeerGroup = proc.getNamedPeerGroups().get(name);
if (_currentNamedPeerGroup == null) {
if (create || _configuration.getVendor() == ConfigurationFormat.ARISTA) {
proc.addNamedPeerGroup(name, definitionLine);
_currentNamedPeerGroup = proc.getNamedPeerGroups().get(name);
} else {
int line = ctx.peergroup.getLine();
_configuration.getUndefinedPeerGroups().put(name, line);
_w.redFlag("reference to undeclared peer group: '" + name + "'");
}
}
pushPeer(_currentNamedPeerGroup);
} else {
throw new BatfishException("unknown neighbor type");
}
}
use of org.batfish.datamodel.Ip6 in project batfish by batfish.
the class CiscoConfiguration method toRoute6FilterLine.
private Route6FilterLine toRoute6FilterLine(ExtendedIpv6AccessListLine fromLine) {
LineAction action = fromLine.getAction();
Ip6 ip = fromLine.getSourceIpWildcard().getIp();
BigInteger minSubnet = fromLine.getDestinationIpWildcard().getIp().asBigInteger();
BigInteger maxSubnet = minSubnet.or(fromLine.getDestinationIpWildcard().getWildcard().asBigInteger());
int minPrefixLength = fromLine.getDestinationIpWildcard().getIp().numSubnetBits();
int maxPrefixLength = new Ip6(maxSubnet).numSubnetBits();
int statedPrefixLength = fromLine.getSourceIpWildcard().getWildcard().inverted().numSubnetBits();
int prefixLength = Math.min(statedPrefixLength, minPrefixLength);
Prefix6 prefix = new Prefix6(ip, prefixLength);
return new Route6FilterLine(action, prefix, new SubRange(minPrefixLength, maxPrefixLength));
}
use of org.batfish.datamodel.Ip6 in project batfish by batfish.
the class Route6FilterLineThrough method applyTo.
@Override
public void applyTo(Route6FilterList rfl) {
int low = _prefix6.getPrefixLength();
int high = _throughPrefix6.getPrefixLength();
for (int i = low; i <= high; i++) {
Ip6 currentNetworkAddress = _throughPrefix6.getAddress().getNetworkAddress(i);
Prefix6 currentPrefix6 = new Prefix6(currentNetworkAddress, i);
org.batfish.datamodel.Route6FilterLine line = new org.batfish.datamodel.Route6FilterLine(LineAction.ACCEPT, currentPrefix6, new SubRange(i, i));
rfl.addLine(line);
}
}
Aggregations