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;
}
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);
}
Aggregations