use of org.batfish.datamodel.SubRange in project batfish by batfish.
the class ConfigurationBuilder method exitFftf_icmp_type.
@Override
public void exitFftf_icmp_type(Fftf_icmp_typeContext ctx) {
if (_currentFirewallFamily == Family.INET6) {
// TODO: support icmpv6
return;
}
SubRange icmpTypeRange;
if (ctx.subrange() != null) {
icmpTypeRange = toSubRange(ctx.subrange());
} else if (ctx.icmp_type() != null) {
int icmpType = toIcmpType(ctx.icmp_type());
icmpTypeRange = new SubRange(icmpType, icmpType);
} else {
throw new BatfishException("Invalid icmp-type");
}
FwFrom from = new FwFromIcmpType(icmpTypeRange);
_currentFwTerm.getFroms().add(from);
}
use of org.batfish.datamodel.SubRange in project batfish by batfish.
the class Batfish method disableUnusableVlanInterfaces.
private void disableUnusableVlanInterfaces(Map<String, Configuration> configurations) {
for (Configuration c : configurations.values()) {
Map<Integer, Interface> vlanInterfaces = new HashMap<>();
Map<Integer, Integer> vlanMemberCounts = new HashMap<>();
Set<Interface> nonVlanInterfaces = new HashSet<>();
Integer vlanNumber = null;
// vlanMemberCounts:
for (Interface iface : c.getInterfaces().values()) {
if ((iface.getInterfaceType() == InterfaceType.VLAN) && ((vlanNumber = CommonUtil.getInterfaceVlanNumber(iface.getName())) != null)) {
vlanInterfaces.put(vlanNumber, iface);
vlanMemberCounts.put(vlanNumber, 0);
} else {
nonVlanInterfaces.add(iface);
}
}
// Update vlanMemberCounts:
for (Interface iface : nonVlanInterfaces) {
List<SubRange> vlans = new ArrayList<>();
vlanNumber = iface.getAccessVlan();
if (vlanNumber == 0) {
// vlan trunked interface
vlans.addAll(iface.getAllowedVlans());
vlanNumber = iface.getNativeVlan();
}
vlans.add(new SubRange(vlanNumber, vlanNumber));
for (SubRange sr : vlans) {
for (int vlanId = sr.getStart(); vlanId <= sr.getEnd(); ++vlanId) {
vlanMemberCounts.compute(vlanId, (k, v) -> (v == null) ? 1 : (v + 1));
}
}
}
// Disable all "normal" vlan interfaces with zero member counts:
String hostname = c.getHostname();
SubRange normalVlanRange = c.getNormalVlanRange();
for (Map.Entry<Integer, Integer> entry : vlanMemberCounts.entrySet()) {
if (entry.getValue() == 0) {
vlanNumber = entry.getKey();
if ((vlanNumber >= normalVlanRange.getStart()) && (vlanNumber <= normalVlanRange.getEnd())) {
Interface iface = vlanInterfaces.get(vlanNumber);
if ((iface != null) && iface.getAutoState()) {
_logger.warnf("WARNING: Disabling unusable vlan interface because no switch port is assigned " + "to it: \"%s:%d\"\n", hostname, vlanNumber);
iface.setActive(false);
iface.setBlacklisted(true);
}
}
}
}
}
}
use of org.batfish.datamodel.SubRange in project batfish by batfish.
the class ConfigurationBuilder method exitFftf_destination_port.
@Override
public void exitFftf_destination_port(Fftf_destination_portContext ctx) {
if (ctx.port() != null) {
int port = getPortNumber(ctx.port());
SubRange subrange = new SubRange(port, port);
FwFrom from = new FwFromDestinationPort(subrange);
_currentFwTerm.getFroms().add(from);
} else if (ctx.range() != null) {
for (SubrangeContext subrangeContext : ctx.range().range_list) {
SubRange subrange = toSubRange(subrangeContext);
FwFrom from = new FwFromDestinationPort(subrange);
_currentFwTerm.getFroms().add(from);
}
}
}
use of org.batfish.datamodel.SubRange in project batfish by batfish.
the class ConfigurationBuilder method exitFftf_port.
@Override
public void exitFftf_port(Fftf_portContext ctx) {
if (ctx.port() != null) {
int port = getPortNumber(ctx.port());
SubRange subrange = new SubRange(port, port);
FwFrom from = new FwFromPort(subrange);
_currentFwTerm.getFroms().add(from);
} else if (ctx.range() != null) {
for (SubrangeContext subrangeContext : ctx.range().range_list) {
SubRange subrange = toSubRange(subrangeContext);
FwFrom from = new FwFromPort(subrange);
_currentFwTerm.getFroms().add(from);
}
}
}
use of org.batfish.datamodel.SubRange in project batfish by batfish.
the class CiscoControlPlaneExtractor method toRoutePolicyPrefixSet.
private RoutePolicyPrefixSet toRoutePolicyPrefixSet(Rp_prefix_setContext ctx) {
if (ctx.name != null) {
// named
String name = ctx.name.getText();
int expressionLine = ctx.name.getStart().getLine();
return new RoutePolicyPrefixSetName(name, expressionLine);
} else {
// inline
PrefixSpace prefixSpace = new PrefixSpace();
Prefix6Space prefix6Space = new Prefix6Space();
boolean ipv6 = false;
for (Prefix_set_elemContext pctxt : ctx.elems) {
int lower;
int upper;
Prefix prefix = null;
Prefix6 prefix6 = null;
if (pctxt.prefix != null) {
prefix = Prefix.parse(pctxt.prefix.getText());
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipa != null) {
prefix = new Prefix(toIp(pctxt.ipa), Prefix.MAX_PREFIX_LENGTH);
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6a != null) {
prefix6 = new Prefix6(toIp6(pctxt.ipv6a), Prefix6.MAX_PREFIX_LENGTH);
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6_prefix != null) {
prefix6 = new Prefix6(pctxt.ipv6_prefix.getText());
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else {
throw new BatfishException("Unhandled alternative");
}
if (pctxt.minpl != null) {
lower = toInteger(pctxt.minpl);
}
if (pctxt.maxpl != null) {
upper = toInteger(pctxt.maxpl);
}
if (pctxt.eqpl != null) {
lower = toInteger(pctxt.eqpl);
upper = lower;
}
if (prefix != null) {
prefixSpace.addPrefixRange(new PrefixRange(prefix, new SubRange(lower, upper)));
} else {
prefix6Space.addPrefix6Range(new Prefix6Range(prefix6, new SubRange(lower, upper)));
ipv6 = true;
}
}
if (ipv6) {
return new RoutePolicyInlinePrefix6Set(prefix6Space);
} else {
return new RoutePolicyInlinePrefixSet(prefixSpace);
}
}
}
Aggregations