Search in sources :

Example 6 with RouteTableId

use of org.onosproject.routeservice.RouteTableId in project onos by opennetworkinglab.

the class DistributedRouteStore method computeRouteTablesFromIps.

private Map<RouteTableId, Set<IpAddress>> computeRouteTablesFromIps(Collection<IpAddress> ipAddresses) {
    Map<RouteTableId, Set<IpAddress>> computedTables = new HashMap<>();
    ipAddresses.forEach(ipAddress -> {
        RouteTableId routeTableId = (ipAddress.isIp4()) ? IPV4 : IPV6;
        Set<IpAddress> tempIpAddresses = computedTables.computeIfAbsent(routeTableId, k -> Sets.newHashSet());
        tempIpAddresses.add(ipAddress);
    });
    return computedTables;
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) RouteSet(org.onosproject.routeservice.RouteSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DistributedSet(org.onosproject.store.service.DistributedSet) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IpAddress(org.onlab.packet.IpAddress)

Example 7 with RouteTableId

use of org.onosproject.routeservice.RouteTableId in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testHostRemovedWithRouteRemoved.

@Test
public void testHostRemovedWithRouteRemoved() {
    Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    // Add a host
    // Expect: add one routing rule and one bridging rule
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
    // Setting up mock route service
    RouteService routeService = hostHandler.srManager.routeService;
    reset(routeService);
    IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
    MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
    VlanId nextHopVlan2 = VlanId.NONE;
    Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
    ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
    Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
    ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
    RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
    RouteTableId routeTableId = new RouteTableId("ipv4");
    expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
    expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
    replay(routeService);
    // Setting up mock device configuration
    hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
    DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
    expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
    deviceConfiguration.removeSubnet(CP11, prefix);
    expectLastCall();
    replay(deviceConfiguration);
    // Remove the host
    // Expect: add the routing rule and the bridging rule
    hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());
    // Expect: subnet is removed from device config
    verify(deviceConfiguration);
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) MacAddress(org.onlab.packet.MacAddress) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) IpPrefix(org.onlab.packet.IpPrefix) DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) RouteService(org.onosproject.routeservice.RouteService) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) RouteInfo(org.onosproject.routeservice.RouteInfo) VlanId(org.onlab.packet.VlanId) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Aggregations

RouteTableId (org.onosproject.routeservice.RouteTableId)7 HashMap (java.util.HashMap)4 Set (java.util.Set)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Route (org.onosproject.routeservice.Route)4 RouteSet (org.onosproject.routeservice.RouteSet)4 IpAddress (org.onlab.packet.IpAddress)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)2 RouteInfo (org.onosproject.routeservice.RouteInfo)2 RouteService (org.onosproject.routeservice.RouteService)2 DistributedSet (org.onosproject.store.service.DistributedSet)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1