use of org.batfish.datamodel.SwitchportEncapsulationType in project batfish by batfish.
the class JuniperConfiguration method toInterface.
private org.batfish.datamodel.Interface toInterface(Interface iface) {
String name = iface.getName();
org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c);
newIface.setDeclaredNames(ImmutableSortedSet.of(name));
Integer mtu = iface.getMtu();
if (mtu != null) {
newIface.setMtu(mtu);
}
newIface.setVrrpGroups(iface.getVrrpGroups());
newIface.setVrf(_c.getVrfs().get(iface.getRoutingInstance()));
Zone zone = _interfaceZones.get(iface);
if (zone != null) {
String zoneName = zone.getName();
// filter for interface in zone
FirewallFilter zoneInboundInterfaceFilter = zone.getInboundInterfaceFilters().get(iface);
if (zoneInboundInterfaceFilter != null) {
String zoneInboundInterfaceFilterName = zoneInboundInterfaceFilter.getName();
zoneInboundInterfaceFilter.getReferers().put(iface, "Interface: '" + iface.getName() + "' refers to inbound filter for interface in zone : '" + zoneName + "'");
IpAccessList zoneInboundInterfaceFilterList = _c.getIpAccessLists().get(zoneInboundInterfaceFilterName);
newIface.setInboundFilter(zoneInboundInterfaceFilterList);
} else {
// filter for zone
FirewallFilter zoneInboundFilter = zone.getInboundFilter();
String zoneInboundFilterName = zoneInboundFilter.getName();
zoneInboundFilter.getReferers().put(iface, "Interface: '" + iface.getName() + "' refers to inbound filter for zone : '" + zoneName + "'");
IpAccessList zoneInboundFilterList = _c.getIpAccessLists().get(zoneInboundFilterName);
newIface.setInboundFilter(zoneInboundFilterList);
}
}
String inAclName = iface.getIncomingFilter();
if (inAclName != null) {
int inAclLine = iface.getIncomingFilterLine();
IpAccessList inAcl = _c.getIpAccessLists().get(inAclName);
if (inAcl == null) {
undefined(JuniperStructureType.FIREWALL_FILTER, inAclName, JuniperStructureUsage.INTERFACE_INCOMING_FILTER, inAclLine);
} else {
FirewallFilter inFilter = _filters.get(inAclName);
inFilter.getReferers().put(iface, "Incoming ACL for interface: " + iface.getName());
newIface.setIncomingFilter(inAcl);
if (inFilter.getRoutingPolicy()) {
RoutingPolicy routingPolicy = _c.getRoutingPolicies().get(inAclName);
if (routingPolicy != null) {
newIface.setRoutingPolicy(inAclName);
} else {
throw new BatfishException("Expected interface routing-policy to exist");
}
}
}
}
String outAclName = iface.getOutgoingFilter();
if (outAclName != null) {
int outAclLine = iface.getOutgoingFilterLine();
IpAccessList outAcl = _c.getIpAccessLists().get(outAclName);
if (outAcl == null) {
undefined(JuniperStructureType.FIREWALL_FILTER, outAclName, JuniperStructureUsage.INTERFACE_OUTGOING_FILTER, outAclLine);
} else {
_filters.get(outAclName).getReferers().put(iface, "Outgoing ACL for interface: " + iface.getName());
newIface.setOutgoingFilter(outAcl);
}
}
if (iface.getPrimaryAddress() != null) {
newIface.setAddress(iface.getPrimaryAddress());
}
newIface.setAllAddresses(iface.getAllAddresses());
newIface.setActive(iface.getActive());
newIface.setAccessVlan(iface.getAccessVlan());
newIface.setNativeVlan(iface.getNativeVlan());
newIface.setSwitchportMode(iface.getSwitchportMode());
SwitchportEncapsulationType swe = iface.getSwitchportTrunkEncapsulation();
if (swe == null) {
swe = SwitchportEncapsulationType.DOT1Q;
}
newIface.setSwitchportTrunkEncapsulation(swe);
newIface.setBandwidth(iface.getBandwidth());
// isis settings
IsisInterfaceSettings isisSettings = iface.getIsisSettings();
IsisInterfaceLevelSettings isisL1Settings = isisSettings.getLevel1Settings();
newIface.setIsisL1InterfaceMode(IsisInterfaceMode.UNSET);
if (isisL1Settings.getEnabled()) {
if (isisSettings.getPassive()) {
newIface.setIsisL1InterfaceMode(IsisInterfaceMode.PASSIVE);
} else if (isisSettings.getEnabled()) {
newIface.setIsisL1InterfaceMode(IsisInterfaceMode.ACTIVE);
}
}
IsisInterfaceLevelSettings isisL2Settings = isisSettings.getLevel2Settings();
newIface.setIsisL2InterfaceMode(IsisInterfaceMode.UNSET);
if (isisL2Settings.getEnabled()) {
if (isisSettings.getPassive()) {
newIface.setIsisL2InterfaceMode(IsisInterfaceMode.PASSIVE);
} else if (isisSettings.getEnabled()) {
newIface.setIsisL2InterfaceMode(IsisInterfaceMode.ACTIVE);
}
}
Integer l1Metric = isisSettings.getLevel1Settings().getMetric();
Integer l2Metric = isisSettings.getLevel2Settings().getMetric();
if (l1Metric != null && l2Metric != null && (l1Metric.intValue() != l2Metric.intValue())) {
_w.unimplemented("distinct metrics for is-is level1 and level2 on an interface");
} else if (l1Metric != null) {
newIface.setIsisCost(l1Metric);
} else if (l2Metric != null) {
newIface.setIsisCost(l2Metric);
}
// TODO: enable/disable individual levels
return newIface;
}
use of org.batfish.datamodel.SwitchportEncapsulationType in project batfish by batfish.
the class CiscoConfiguration method toInterface.
private org.batfish.datamodel.Interface toInterface(Interface iface, Map<String, IpAccessList> ipAccessLists, Configuration c) {
String name = iface.getName();
org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, c);
String vrfName = iface.getVrf();
Vrf vrf = _vrfs.computeIfAbsent(vrfName, Vrf::new);
newIface.setDescription(iface.getDescription());
newIface.setActive(iface.getActive());
newIface.setAutoState(iface.getAutoState());
newIface.setVrf(c.getVrfs().get(vrfName));
newIface.setBandwidth(iface.getBandwidth());
if (iface.getDhcpRelayClient()) {
newIface.getDhcpRelayAddresses().addAll(_dhcpRelayServers);
} else {
newIface.getDhcpRelayAddresses().addAll(iface.getDhcpRelayAddresses());
}
newIface.setMtu(getInterfaceMtu(iface));
newIface.setOspfPointToPoint(iface.getOspfPointToPoint());
newIface.setProxyArp(iface.getProxyArp());
newIface.setSpanningTreePortfast(iface.getSpanningTreePortfast());
newIface.setSwitchport(iface.getSwitchport());
newIface.setDeclaredNames(ImmutableSortedSet.copyOf(iface.getDeclaredNames()));
// All prefixes is the combination of the interface prefix + any secondary prefixes.
ImmutableSet.Builder<InterfaceAddress> allPrefixes = ImmutableSet.builder();
if (iface.getAddress() != null) {
newIface.setAddress(iface.getAddress());
allPrefixes.add(iface.getAddress());
}
allPrefixes.addAll(iface.getSecondaryAddresses());
newIface.setAllAddresses(allPrefixes.build());
Long ospfAreaLong = iface.getOspfArea();
if (ospfAreaLong != null) {
OspfProcess proc = vrf.getOspfProcess();
if (proc != null) {
if (iface.getOspfActive()) {
proc.getActiveInterfaceList().add(name);
}
if (iface.getOspfPassive()) {
proc.getPassiveInterfaceList().add(name);
}
for (InterfaceAddress address : newIface.getAllAddresses()) {
Prefix prefix = address.getPrefix();
OspfNetwork ospfNetwork = new OspfNetwork(prefix, ospfAreaLong);
proc.getNetworks().add(ospfNetwork);
}
} else {
_w.redFlag("Interface: '" + name + "' contains OSPF settings, but there is no OSPF process");
}
}
boolean level1 = false;
boolean level2 = false;
IsisProcess isisProcess = vrf.getIsisProcess();
if (isisProcess != null) {
switch(isisProcess.getLevel()) {
case LEVEL_1:
level1 = true;
break;
case LEVEL_1_2:
level1 = true;
level2 = true;
break;
case LEVEL_2:
level2 = true;
break;
default:
throw new VendorConversionException("Invalid IS-IS level");
}
}
if (level1) {
newIface.setIsisL1InterfaceMode(iface.getIsisInterfaceMode());
} else {
newIface.setIsisL1InterfaceMode(IsisInterfaceMode.UNSET);
}
if (level2) {
newIface.setIsisL2InterfaceMode(iface.getIsisInterfaceMode());
} else {
newIface.setIsisL2InterfaceMode(IsisInterfaceMode.UNSET);
}
newIface.setIsisCost(iface.getIsisCost());
newIface.setOspfCost(iface.getOspfCost());
newIface.setOspfDeadInterval(iface.getOspfDeadInterval());
newIface.setOspfHelloMultiplier(iface.getOspfHelloMultiplier());
// switch settings
newIface.setAccessVlan(iface.getAccessVlan());
newIface.setNativeVlan(iface.getNativeVlan());
newIface.setSwitchportMode(iface.getSwitchportMode());
SwitchportEncapsulationType encapsulation = iface.getSwitchportTrunkEncapsulation();
if (encapsulation == null) {
// no encapsulation set, so use default..
// TODO: check if this is OK
encapsulation = SwitchportEncapsulationType.DOT1Q;
}
newIface.setSwitchportTrunkEncapsulation(encapsulation);
newIface.addAllowedRanges(iface.getAllowedVlans());
String incomingFilterName = iface.getIncomingFilter();
if (incomingFilterName != null) {
int incomingFilterLine = iface.getIncomingFilterLine();
IpAccessList incomingFilter = ipAccessLists.get(incomingFilterName);
if (incomingFilter == null) {
undefined(CiscoStructureType.IP_ACCESS_LIST, incomingFilterName, CiscoStructureUsage.INTERFACE_INCOMING_FILTER, incomingFilterLine);
} else {
String msg = "incoming acl for interface: " + iface.getName();
ExtendedAccessList incomingExtendedAccessList = _extendedAccessLists.get(incomingFilterName);
if (incomingExtendedAccessList != null) {
incomingExtendedAccessList.getReferers().put(iface, msg);
}
StandardAccessList incomingStandardAccessList = _standardAccessLists.get(incomingFilterName);
if (incomingStandardAccessList != null) {
incomingStandardAccessList.getReferers().put(iface, msg);
}
}
newIface.setIncomingFilter(incomingFilter);
}
String outgoingFilterName = iface.getOutgoingFilter();
if (outgoingFilterName != null) {
int outgoingFilterLine = iface.getOutgoingFilterLine();
IpAccessList outgoingFilter = ipAccessLists.get(outgoingFilterName);
if (outgoingFilter == null) {
undefined(CiscoStructureType.IP_ACCESS_LIST, outgoingFilterName, CiscoStructureUsage.INTERFACE_OUTGOING_FILTER, outgoingFilterLine);
} else {
String msg = "outgoing acl for interface: " + iface.getName();
ExtendedAccessList outgoingExtendedAccessList = _extendedAccessLists.get(outgoingFilterName);
if (outgoingExtendedAccessList != null) {
outgoingExtendedAccessList.getReferers().put(iface, msg);
}
StandardAccessList outgoingStandardAccessList = _standardAccessLists.get(outgoingFilterName);
if (outgoingStandardAccessList != null) {
outgoingStandardAccessList.getReferers().put(iface, msg);
}
}
newIface.setOutgoingFilter(outgoingFilter);
}
List<CiscoSourceNat> origSourceNats = iface.getSourceNats();
if (origSourceNats != null) {
// Process each of the CiscoSourceNats:
// 1) Collect references to ACLs and NAT pools.
// 2) For valid CiscoSourceNat rules, add them to the newIface source NATs list.
newIface.setSourceNats(origSourceNats.stream().map(nat -> processSourceNat(nat, iface, ipAccessLists)).filter(Objects::nonNull).collect(ImmutableList.toImmutableList()));
}
String routingPolicyName = iface.getRoutingPolicy();
if (routingPolicyName != null) {
int routingPolicyLine = iface.getRoutingPolicyLine();
RouteMap routingPolicyRouteMap = _routeMaps.get(routingPolicyName);
if (routingPolicyRouteMap == null) {
undefined(CiscoStructureType.ROUTE_MAP, routingPolicyName, CiscoStructureUsage.INTERFACE_POLICY_ROUTING_MAP, routingPolicyLine);
} else {
routingPolicyRouteMap.getReferers().put(iface, "routing policy for interface: " + iface.getName());
}
newIface.setRoutingPolicy(routingPolicyName);
}
return newIface;
}
Aggregations