/** * Set the primary address and secondary addresses of the interface. <br> * The {@link Interface#getAllAddresses()} method of the built {@link Interface} will return a * set containing the primary address and secondary addresses.<br> * The node will accept traffic whose destination IP is among any of the addresses of any of the * interfaces. The primary address is the one used by default as the source IP for traffic sent * out the interface. A secondary address is another address potentially associated with a * different subnet living on the interface. The interface will reply to ARP for the primary or * any secondary IP. */ public Builder setAddresses( InterfaceAddress primaryAddress, InterfaceAddress... secondaryAddresses) { return setAddresses(primaryAddress, Arrays.asList(secondaryAddresses)); }
ib.setActive(true) .setAddresses(uniqueAddr, secondaryUniqueAddr) .setName("Eth2/2") .build()));
InterfaceAddress primary = new InterfaceAddress(P1.getStartIp(), P1.getPrefixLength()); InterfaceAddress secondary = new InterfaceAddress(P2.getStartIp(), P2.getPrefixLength()); Interface iNoProxyArp = _ib.setAddresses(primary, secondary).build(); Interface iProxyArp = _ib.setProxyArp(true).build(); IpSpace routableIpsForThisVrf = UniverseIpSpace.INSTANCE;
.setAddresses(new InterfaceAddress("2.0.0.2/31")) .setOwner(c2) .setVrf(v2)
private SortedMap<String, Configuration> generateConfigs(boolean delta) { Configuration node1 = _cb.setHostname(NODE1).build(); Vrf v1 = _vb.setOwner(node1).build(); _ib.setOwner(node1).setVrf(v1); _ib.setName(LOOPBACK).setAddresses(new InterfaceAddress("1.1.1.1/32")).build(); _ib.setName(PHYSICAL).setAddresses(new InterfaceAddress("1.1.1.2/31")).build(); if (!delta) { v1.setStaticRoutes( ImmutableSortedSet.of( StaticRoute.builder() .setAdministrativeCost(1) .setNetwork(Prefix.parse("2.2.2.2/32")) .setNextHopInterface(PHYSICAL) .build())); } Configuration node2 = _cb.setHostname(NODE2).build(); Vrf v2 = _vb.setOwner(node2).build(); _ib.setOwner(node2).setVrf(v2); _ib.setName(PHYSICAL) .setAddresses(new InterfaceAddress("1.1.1.3/31"), new InterfaceAddress("2.2.2.2/32")) .build(); v2.setStaticRoutes( ImmutableSortedSet.of( StaticRoute.builder() .setNetwork(Prefix.parse("1.1.1.1/32")) .setNextHopInterface(PHYSICAL) .setAdministrativeCost(1) .build())); return ImmutableSortedMap.of(NODE1, node1, NODE2, node2); }
@Test public void testSynthesizeTopology_selfEdges() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf v1 = nf.vrfBuilder().setOwner(c).setName("v1").build(); Vrf v2 = nf.vrfBuilder().setOwner(c).setName("v2").build(); Interface.Builder builder = nf.interfaceBuilder().setOwner(c); Interface i1 = builder.setAddresses(new InterfaceAddress("1.2.3.4/24")).setVrf(v1).build(); Interface i2 = builder.setAddresses(new InterfaceAddress("1.2.3.5/24")).setVrf(v1).build(); Interface i3 = builder.setAddresses(new InterfaceAddress("1.2.3.6/24")).setVrf(v2).build(); Topology t = TopologyUtil.synthesizeL3Topology(ImmutableMap.of(c.getHostname(), c)); assertThat( t.getEdges(), equalTo( ImmutableSet.of( new Edge(i1, i3), new Edge(i3, i1), new Edge(i2, i3), new Edge(i3, i2)))); }
@Test public void testSynthesizeTopology_asymmetric() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = cb.build(); Configuration c2 = cb.build(); Interface i1 = nf.interfaceBuilder().setOwner(c1).setAddresses(new InterfaceAddress("1.2.3.4/24")).build(); Interface i2 = nf.interfaceBuilder().setOwner(c2).setAddresses(new InterfaceAddress("1.2.3.5/28")).build(); Topology t = TopologyUtil.synthesizeL3Topology( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)); assertThat(t.getEdges(), equalTo(ImmutableSet.of(new Edge(i1, i2), new Edge(i2, i1)))); }
public Interface toInterface(Configuration configuration, Warnings warnings) { String name = _canonicalName != null ? _canonicalName : _name; Interface.Builder iface = Interface.builder() .setName(name) .setOwner(configuration) .setAddresses(_address, _otherAddresses) .setBandwidth(_bandwidth) .setDeclaredNames(ImmutableSortedSet.of(_name)) .setProxyArp(false) .setVrf(configuration.getDefaultVrf()); if (_shared) { Ip publicIp = _address.getIp(); iface.setOutgoingTransformation(always().apply(assignSourceIp(publicIp, publicIp)).build()); } return iface.build(); } }
@Test public void testSynthesizeTopology_asymmetricSharedIp() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = cb.build(); Configuration c2 = cb.build(); nf.interfaceBuilder().setOwner(c1).setAddresses(new InterfaceAddress("1.2.3.4/24")).build(); nf.interfaceBuilder().setOwner(c2).setAddresses(new InterfaceAddress("1.2.3.4/28")).build(); Topology t = TopologyUtil.synthesizeL3Topology( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)); assertThat(t.getEdges(), empty()); } }
@Test public void testComputeIpsAssignedToThisInterface() { Configuration config = _cb.build(); Map<String, Configuration> configs = ImmutableMap.of(config.getHostname(), config); _ib.setOwner(config); InterfaceAddress primary = new InterfaceAddress(P1.getStartIp(), P1.getPrefixLength()); InterfaceAddress secondary = new InterfaceAddress(P2.getStartIp(), P2.getPrefixLength()); Interface i = _ib.setAddresses(primary, secondary).build(); _interfaceOwnedIps = TopologyUtil.computeInterfaceOwnedIps(configs, false); ForwardingAnalysisImpl forwardingAnalysisImpl = initForwardingAnalysisImpl(); IpSpace result = forwardingAnalysisImpl.computeIpsAssignedToThisInterface(i); assertThat(result, containsIp(P1.getStartIp())); assertThat(result, containsIp(P2.getStartIp())); assertThat(result, not(containsIp(P2.getEndIp()))); }
@Test public void testSynthesizeTopology_asymmetricPartialOverlap() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = cb.build(); Configuration c2 = cb.build(); nf.interfaceBuilder().setOwner(c1).setAddresses(new InterfaceAddress("1.2.3.4/24")).build(); nf.interfaceBuilder().setOwner(c2).setAddresses(new InterfaceAddress("1.2.3.17/28")).build(); Topology t = TopologyUtil.synthesizeL3Topology( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)); assertThat(t.getEdges(), empty()); }