use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Instance method toConfigurationNode.
public Configuration toConfigurationNode(AwsConfiguration awsVpcConfig, Region region, Warnings warnings) {
String name = _tags.getOrDefault("Name", _instanceId);
Configuration cfgNode = Utils.newAwsConfiguration(name, "aws");
for (String interfaceId : _networkInterfaces) {
NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId);
if (netInterface == null) {
warnings.redFlag(String.format("Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId));
continue;
}
ImmutableSortedSet.Builder<InterfaceAddress> ifaceAddressesBuilder = new ImmutableSortedSet.Builder<>(Comparator.naturalOrder());
Subnet subnet = region.getSubnets().get(netInterface.getSubnetId());
Prefix ifaceSubnet = subnet.getCidrBlock();
Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp();
StaticRoute defaultRoute = StaticRoute.builder().setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN).setMetric(Route.DEFAULT_STATIC_ROUTE_COST).setNextHopIp(defaultGatewayAddress).setNetwork(Prefix.ZERO).build();
cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute);
for (Ip ip : netInterface.getIpAddressAssociations().keySet()) {
if (!ifaceSubnet.containsIp(ip)) {
warnings.pedantic(String.format("Instance subnet \"%s\" does not contain private ip: \"%s\"", ifaceSubnet, ip));
continue;
}
if (ip.equals(ifaceSubnet.getEndIp())) {
warnings.pedantic(String.format("Expected end address \"%s\" to be used by generated subnet node", ip));
continue;
}
InterfaceAddress address = new InterfaceAddress(ip, ifaceSubnet.getPrefixLength());
ifaceAddressesBuilder.add(address);
}
SortedSet<InterfaceAddress> ifaceAddresses = ifaceAddressesBuilder.build();
Interface iface = Utils.newInterface(interfaceId, cfgNode, ifaceAddresses.first());
iface.setAllAddresses(ifaceAddresses);
cfgNode.getVendorFamily().getAws().setVpcId(_vpcId);
cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId);
cfgNode.getVendorFamily().getAws().setRegion(region.getName());
}
Utils.processSecurityGroups(region, cfgNode, _securityGroups, warnings);
return cfgNode;
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class IptablesVendorConfiguration method applyAsOverlay.
public void applyAsOverlay(Configuration configuration, Warnings warnings) {
IpAccessList prerouting = configuration.getIpAccessLists().remove("mangle::PREROUTING");
IpAccessList postrouting = configuration.getIpAccessLists().remove("mangle::POSTROUTING");
if (!configuration.getIpAccessLists().isEmpty()) {
throw new BatfishException("Merging iptables rules for " + configuration.getName() + ": only mangle tables are supported");
}
if (prerouting != null) {
for (Interface i : configuration.getInterfaces().values()) {
String dbgName = configuration.getHostname() + ":" + i.getName();
List<IpAccessListLine> newRules = prerouting.getLines().stream().filter(l -> {
String iface = _lineInInterfaces.get(l);
return iface == null || i.getName().equals(iface);
}).collect(Collectors.toList());
if (i.getIncomingFilter() != null) {
throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
}
String aclName = "iptables_" + i.getName() + "_ingress";
IpAccessList acl = new IpAccessList(aclName, newRules);
if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
throw new BatfishException(dbgName + " acl " + aclName + " already exists");
}
i.setIncomingFilter(acl);
}
}
if (postrouting != null) {
for (Interface i : configuration.getInterfaces().values()) {
String dbgName = configuration.getHostname() + ":" + i.getName();
List<IpAccessListLine> newRules = postrouting.getLines().stream().filter(l -> {
String iface = _lineOutInterfaces.get(l);
return iface == null || i.getName().equals(iface);
}).collect(Collectors.toList());
if (i.getOutgoingFilter() != null) {
throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
}
String aclName = "iptables_" + i.getName() + "_egress";
IpAccessList acl = new IpAccessList(aclName, newRules);
if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
throw new BatfishException(dbgName + " acl " + aclName + " already exists");
}
i.setOutgoingFilter(acl);
}
}
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class HostInterface method toInterface.
public Interface toInterface(Configuration configuration, Warnings warnings) {
String name = _canonicalName != null ? _canonicalName : _name;
Interface.Builder iface = Interface.builder().setName(name).setOwner(configuration).setActive(true).setAddresses(_address, _otherAddresses).setBandwidth(_bandwidth).setDeclaredNames(ImmutableSortedSet.of(_name)).setProxyArp(false).setVrf(configuration.getDefaultVrf());
if (_shared) {
SourceNat sourceNat = new SourceNat();
Ip publicIp = _address.getIp();
sourceNat.setPoolIpFirst(publicIp);
sourceNat.setPoolIpLast(publicIp);
iface.setSourceNats(ImmutableList.of(sourceNat));
}
return iface.build();
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Encoder method initFailedLinkVariables.
/*
* Initialize symbolic variables to represent link failures.
*/
private void initFailedLinkVariables() {
for (List<GraphEdge> edges : _graph.getEdgeMap().values()) {
for (GraphEdge ge : edges) {
if (ge.getPeer() == null) {
Interface i = ge.getStart();
String name = getId() + "_FAILED-EDGE_" + ge.getRouter() + "_" + i.getName();
ArithExpr var = getCtx().mkIntConst(name);
_symbolicFailures.getFailedEdgeLinks().put(ge, var);
_allVariables.put(var.toString(), var);
}
}
}
for (Entry<String, Set<String>> entry : _graph.getNeighbors().entrySet()) {
String router = entry.getKey();
Set<String> peers = entry.getValue();
for (String peer : peers) {
// sort names for unique
String pair = (router.compareTo(peer) < 0 ? router + "_" + peer : peer + "_" + router);
String name = getId() + "_FAILED-EDGE_" + pair;
ArithExpr var = _ctx.mkIntConst(name);
_symbolicFailures.getFailedInternalLinks().put(router, peer, var);
_allVariables.put(var.toString(), var);
}
}
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class EncoderSlice method equalAreas.
/*
* Creates a test to check for equal ospf areas
* tags after accounting for null values introduced by optimizations
*/
private BoolExpr equalAreas(SymbolicRoute best, SymbolicRoute vars, @Nullable LogicalEdge e) {
BoolExpr equalOspfArea;
boolean hasBestArea = (best.getOspfArea() != null && best.getOspfArea().getBitVec() != null);
boolean hasVarsArea = (vars.getOspfArea() != null && vars.getOspfArea().getBitVec() != null);
if (e != null) {
if (hasBestArea) {
Interface iface = e.getEdge().getStart();
if (hasVarsArea) {
equalOspfArea = best.getOspfArea().mkEq(vars.getOspfArea());
} else if (iface.getOspfAreaName() != null) {
equalOspfArea = best.getOspfArea().checkIfValue(iface.getOspfAreaName());
} else {
equalOspfArea = best.getOspfArea().isDefaultValue();
}
} else {
equalOspfArea = mkTrue();
}
} else {
equalOspfArea = mkTrue();
}
return equalOspfArea;
}
Aggregations