@Override public Set<Interface> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(_shorthandSpecifier::matches) .collect(Collectors.toSet()); } }
public NodeSummary(Configuration node) { if (!node.getAsPathAccessLists().isEmpty()) { _asPathAccessLists = node.getAsPathAccessLists().navigableKeySet(); if (!node.getCommunityLists().isEmpty()) { _communityLists = node.getCommunityLists().navigableKeySet(); _configurationFormat = node.getConfigurationFormat(); if (!node.getAllInterfaces().isEmpty()) { _interfaces = node.getAllInterfaces().navigableKeySet(); if (!node.getIkePhase1Keys().isEmpty()) { _ikePhase1Keys = node.getIkePhase1Keys().navigableKeySet(); if (!node.getIkePhase1Policies().isEmpty()) { _ikePhase1Policies = node.getIkePhase1Policies().navigableKeySet(); if (!node.getIkePhase1Proposals().isEmpty()) { _ikePhase1Proposals = node.getIkePhase1Proposals().navigableKeySet(); if (!node.getIpAccessLists().isEmpty()) { _ipAccessLists = node.getIpAccessLists().navigableKeySet(); if (!node.getIpsecPeerConfigs().isEmpty()) { _ipsecPeerConfigs = node.getIpsecPeerConfigs().navigableKeySet(); if (!node.getIpsecPhase2Policies().isEmpty()) { _ipsecPhase2Policies = node.getIpsecPhase2Policies().navigableKeySet(); if (!node.getIpsecPhase2Proposals().isEmpty()) {
@JsonCreator private static Configuration makeConfiguration( @JsonProperty(PROP_NAME) String hostname, @Nullable @JsonProperty(PROP_CONFIGURATION_FORMAT) ConfigurationFormat configurationFormat) { if (configurationFormat == null) { throw new BatfishException("Configuration format cannot be null"); } return new Configuration(hostname, configurationFormat); }
@Override public List<Configuration> toVendorIndependentConfigurations() throws VendorConversionException { _c = new Configuration(_hostname, _vendor); _c.setDefaultCrossZoneAction(LineAction.PERMIT); _c.setDefaultInboundAction(LineAction.PERMIT); return ImmutableList.of(_c); } }
public static BDDSourceManager forIpAccessList( BDDPacket pkt, Configuration config, IpAccessList acl) { return forIpAccessList( pkt, Sets.union(ImmutableSet.of(SOURCE_ORIGINATING_FROM_DEVICE), config.activeInterfaces()), config.getIpAccessLists(), acl); }
private Configuration createAbstractConfig(Set<String> abstractRouters, Configuration conf) { Configuration abstractConf = new Configuration(conf.getHostname(), conf.getConfigurationFormat()); abstractConf.setDnsServers(conf.getDnsServers()); abstractConf.setDnsSourceInterface(conf.getDnsSourceInterface()); abstractConf.setDomainName(conf.getDomainName()); abstractConf.setAuthenticationKeyChains(conf.getAuthenticationKeyChains()); abstractConf.setDefaultCrossZoneAction(conf.getDefaultCrossZoneAction()); abstractConf.setIkePhase1Keys(conf.getIkePhase1Keys()); abstractConf.setIkePhase1Policies(conf.getIkePhase1Policies()); abstractConf.setIkePhase1Proposals(conf.getIkePhase1Proposals()); abstractConf.setDefaultInboundAction(conf.getDefaultInboundAction()); abstractConf.setIpAccessLists(conf.getIpAccessLists()); abstractConf.setIp6AccessLists(conf.getIp6AccessLists()); abstractConf.setRouteFilterLists(conf.getRouteFilterLists()); abstractConf.setRoute6FilterLists(conf.getRoute6FilterLists()); abstractConf.setIpsecPeerConfigs(conf.getIpsecPeerConfigs()); abstractConf.setIpsecPhase2Policies(conf.getIpsecPhase2Policies()); abstractConf.setIpsecPhase2Proposals(conf.getIpsecPhase2Proposals()); abstractConf.setLoggingServers(conf.getLoggingServers()); abstractConf.setLoggingSourceInterface(conf.getLoggingSourceInterface()); abstractConf.setNormalVlanRange(conf.getNormalVlanRange()); abstractConf.setNtpServers(conf.getNtpServers()); abstractConf.setNtpSourceInterface(conf.getNtpSourceInterface()); abstractConf.setSnmpSourceInterface(conf.getSnmpSourceInterface()); abstractConf.setSnmpTrapServers(conf.getSnmpTrapServers()); abstractConf.setTacacsServers(conf.getTacacsServers()); abstractConf.setTacacsSourceInterface(conf.getTacacsSourceInterface()); abstractConf.setVendorFamily(conf.getVendorFamily()); abstractConf.setZones(conf.getZones());
@Override public List<Configuration> toVendorIndependentConfigurations() { final Configuration c = new Configuration(_hostname, _vendor); c.getVendorFamily().setCisco(_cf); c.setDefaultInboundAction(LineAction.PERMIT); c.setDefaultCrossZoneAction(LineAction.PERMIT); c.setDnsServers(_dnsServers); c.setDnsSourceInterface(_dnsSourceInterface); c.setDomainName(_domainName); c.setNormalVlanRange(new SubRange(VLAN_NORMAL_MIN_CISCO, VLAN_NORMAL_MAX_CISCO)); c.setTacacsServers(_tacacsServers); c.setTacacsSourceInterface(_tacacsSourceInterface); c.setNtpSourceInterface(_ntpSourceInterface); if (_cf.getNtp() != null) { c.setNtpServers(new TreeSet<>(_cf.getNtp().getServers().keySet())); c.setLoggingSourceInterface(_cf.getLogging().getSourceInterface()); c.setLoggingServers(new TreeSet<>(_cf.getLogging().getHosts().keySet())); c.setSnmpSourceInterface(_snmpSourceInterface); c.getVrfs().put(vrfName, new org.batfish.datamodel.Vrf(vrfName)); c.getVrfs().get(snmpServerVrf).setSnmpServer(_snmpServer); c.getAsPathAccessLists().put(apList.getName(), apList); c.getAsPathAccessLists().put(apList.getName(), apList); c.getCommunityLists().put(cList.getName(), cList);
private Configuration toVendorIndependentConfiguration() throws VendorConversionException { String hostname = getHostname(); _c = new Configuration(hostname, _vendor); _c.setAuthenticationKeyChains( convertAuthenticationKeyChains(_masterLogicalSystem.getAuthenticationKeyChains())); _c.setDnsServers(_masterLogicalSystem.getDnsServers()); _c.setDomainName(_masterLogicalSystem.getDefaultRoutingInstance().getDomainName()); _c.setLoggingServers(_masterLogicalSystem.getSyslogHosts()); _c.setNtpServers(_masterLogicalSystem.getNtpServers()); _c.setTacacsServers(_masterLogicalSystem.getTacplusServers()); _c.getVendorFamily().setJuniper(_masterLogicalSystem.getJf()); for (String riName : _masterLogicalSystem.getRoutingInstances().keySet()) { _c.getVrfs().put(riName, new Vrf(riName)); _c.getRouteFilterLists().put(name, rfl); (name, addressBook) -> { Map<String, IpSpace> ipspaces = toIpSpaces(name, addressBook); _c.getIpSpaces().putAll(ipspaces); ipspaces .keySet() .forEach( ipSpaceName -> _c.getIpSpaceMetadata() .put( ipSpaceName, _c.getIpAccessLists().put(name, list); _c.getRoutingPolicies().put(name, routingPolicy);
public ConfigurationDiff(Configuration before, Configuration after) { _asPathAccessListsDiff = new AsPathAccessListsDiff(before.getAsPathAccessLists(), after.getAsPathAccessLists()); if (_asPathAccessListsDiff.isEmpty()) { _asPathAccessListsDiff = null; new CommunityListsDiff(before.getCommunityLists(), after.getCommunityLists()); if (_communityListsDiff.isEmpty()) { _communityListsDiff = null; _interfacesDiff = new InterfacesDiff(before.getAllInterfaces(), after.getAllInterfaces()); if (_interfacesDiff.isEmpty()) { _interfacesDiff = null; _ipAccessListsDiff = new IpAccessListsDiff(before.getIpAccessLists(), after.getIpAccessLists()); if (_ipAccessListsDiff.isEmpty()) { _ipAccessListsDiff = null; _vrfsDiff = new VrfsDiff(before.getVrfs(), after.getVrfs()); if (_vrfsDiff.isEmpty()) { _vrfsDiff = null; new RouteFilterListsDiff(before.getRouteFilterLists(), after.getRouteFilterLists()); if (_routeFilterListsDiff.isEmpty()) { _routeFilterListsDiff = null; new RoutingPoliciesDiff(before.getRoutingPolicies(), after.getRoutingPolicies()); if (_routingPoliciesDiff.isEmpty()) { _routingPoliciesDiff = null;
VirtualEigrpProcess(final EigrpProcess process, final String vrfName, final Configuration c) { _asn = process.getAsn(); _defaultExternalAdminCost = RoutingProtocol.EIGRP_EX.getDefaultAdministrativeCost(c.getConfigurationFormat()); _defaultInternalAdminCost = RoutingProtocol.EIGRP.getDefaultAdministrativeCost(c.getConfigurationFormat()); _externalRib = new EigrpExternalRib(); _externalStagingRib = new EigrpExternalRib(); for (String ifaceName : c.getVrfs().get(vrfName).getInterfaceNames()) { Interface iface = c.getAllInterfaces().get(ifaceName); if (iface.getActive() && iface.getEigrp() != null && iface.getEigrp().getAsn() == _asn && iface.getEigrp().getEnabled()) { _interfaces.add(new EigrpInterface(c.getHostname(), iface)); requireNonNull(iface.getEigrp()); Set<Prefix> allNetworkPrefixes = .setAdmin( RoutingProtocol.EIGRP.getDefaultAdministrativeCost( c.getConfigurationFormat())) .setEigrpMetric(iface.getEigrp().getMetric()) .setNetwork(prefix) _exportPolicy = c.getRoutingPolicies().get(exportPolicyName); } else { _exportPolicy = null;
@Override protected Map<String, IpAccessList> featureValueOf(Configuration actual) { return actual.getIpAccessLists(); } }
private void identifyDeviceTypes(Collection<Configuration> configurations) { for (Configuration c : configurations) { if (c.getDeviceType() != null) { continue; } // Set device type to host iff the configuration format is HOST if (c.getConfigurationFormat() == ConfigurationFormat.HOST) { c.setDeviceType(DeviceType.HOST); } else if (c.getVrfs().values().stream() .anyMatch( vrf -> vrf.getBgpProcess() != null || !vrf.getEigrpProcesses().isEmpty() || vrf.getOspfProcess() != null || vrf.getRipProcess() != null)) { // If any vrf on device has BGP, EIGRP, OSPF, or RIP, set device type to router c.setDeviceType(DeviceType.ROUTER); } else { // If device was not a host or router, call it a switch c.setDeviceType(DeviceType.SWITCH); } } }
private TransformationToTransition initTransformationToTransformation(Configuration node) { return new TransformationToTransition( _bddPacket, new IpAccessListToBDD( _bddPacket, _bddSourceManagers.get(node.getHostname()), new HeaderSpaceToBDD( _bddPacket, node.getIpSpaces(), _dstIpSpaceToBDD, _srcIpSpaceToBDD), node.getIpAccessLists())); }
String node = _c.getHostname(); int adminCost = RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat()); SortedSet<Edge> edges = topology.getNodeEdges().get(node); if (edges == null) { Node neighbor = nodes.get(neighborName); Interface neighborInterface = neighbor.getConfiguration().getAllInterfaces().get(edge.getInt2());
@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())); } }
private Map<String, AclLineMatchExprToBooleanExpr> computeAclLineMatchExprToBooleanExprs() { return toImmutableMap( _configurations, Entry::getKey, e -> { Configuration config = e.getValue(); return new AclLineMatchExprToBooleanExpr( config.getIpAccessLists(), config.getIpSpaces(), _sourceInterfaceField, _sourceInterfaceFieldValues.getOrDefault(e.getKey(), ImmutableMap.of())); }); }
private @Nonnull CommunitySetExpr resolve(@Nonnull Environment environment) { return requireNonNull(environment.getConfiguration().getCommunityLists().get(_name)); } }
if (ge.getStart().isLoopback(conf.getConfigurationFormat())) { return proto.isConnected(); List<StaticRoute> srs = getStaticRoutes().get(conf.getHostname(), iface.getName()); return iface.getActive() && srs != null && !srs.isEmpty();
c.setIpsecPhase2Policies( ipsecPhase2PolicyBuilder .putAll(c.getIpsecPhase2Policies()) .put(ipsecPhase2PolicyName, ipsecPhase2Policy) .build()); c.setIpsecPeerConfigs( ipsecPeerConfigsBuilder .putAll(c.getIpsecPeerConfigs()) .putAll( toIpsecPeerConfigs(
private static Configuration createTestConfiguration( String nodeName, ConfigurationFormat configFormat, String... interfaceNames) { Configuration config = new Configuration(nodeName, configFormat); for (String interfaceName : interfaceNames) { config.getAllInterfaces().put(interfaceName, new Interface(interfaceName, config)); } return config; }