Search in sources :

Example 31 with DefaultHost

use of org.onosproject.net.DefaultHost in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testHostAdded.

@Test
public void testHostAdded() {
    Host subject;
    // Untagged host discovered on untagged port
    // Expect: add one routing rule and one bridging rule
    subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    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)));
    // Untagged host discovered on tagged/native port
    // Expect: add one routing rule and one bridging rule
    subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(2, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertEquals(2, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
    // Tagged host discovered on untagged port
    // Expect: ignore the host. No rule is added.
    subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED, Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(2, ROUTING_TABLE.size());
    assertEquals(2, BRIDGING_TABLE.size());
    // Tagged host discovered on tagged port with the same IP
    // Expect: update existing route, add one bridging rule
    subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED, Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(2, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertEquals(HOST_VLAN_TAGGED, ROUTING_TABLE.get(new MockRoutingTableKey(HOST_LOC13.deviceId(), HOST_IP21.toIpPrefix())).vlanId);
    assertEquals(3, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, HOST_VLAN_TAGGED)));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 32 with DefaultHost

use of org.onosproject.net.DefaultHost in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testDualHomedHostMoveToInvalidLocation.

@Test
public void testDualHomedHostMoveToInvalidLocation() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
    Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC61, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
    // Add a host
    // Expect: add two new routing rules, two new bridging rules
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(2, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Move first host location to an invalid location
    // Expect: One routing and one bridging flow
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(1, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Move second host location to an invalid location
    // Expect: No routing or bridging rule
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());
    // Move second host location back to a valid location
    // Expect: One routing and one bridging flow
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
    assertEquals(1, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(1, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Move first host location back to a valid location
    // Expect: Two routing and two bridging flow
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
    assertEquals(2, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 33 with DefaultHost

use of org.onosproject.net.DefaultHost in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testDelayedIpAndLocation.

@Test
public void testDelayedIpAndLocation() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
    Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
    // Add a dual-home host with only one location and no IP
    // Expect: only bridging redirection works
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Discover IP
    // Expect: routing redirection should also work
    hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host1));
    assertEquals(2, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Expect probe to be sent out on pair device
    assertTrue(mockLocationProbingService.verifyProbe(host2, CP41, ProbeMode.DISCOVER));
    // Discover location
    // Expect: cancel all redirections
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
    assertEquals(2, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 34 with DefaultHost

use of org.onosproject.net.DefaultHost in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testDualHomingBothLocationFail.

@Test
public void testDualHomingBothLocationFail() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
    // Add a host
    // Expect: add four new routing rules, two new bridging rules
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(4, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Host becomes single-homed
    // Expect: redirect flows from host location to pair link
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
    assertEquals(4, ROUTING_TABLE.size());
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
    assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
    assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
    assertEquals(2, BRIDGING_TABLE.size());
    assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
    // Host loses both locations
    // Expect: Remove last location and all previous redirection flows
    hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, host2));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 35 with DefaultHost

use of org.onosproject.net.DefaultHost 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

DefaultHost (org.onosproject.net.DefaultHost)36 Host (org.onosproject.net.Host)28 Test (org.junit.Test)27 HostEvent (org.onosproject.net.host.HostEvent)20 HostLocation (org.onosproject.net.HostLocation)13 IpAddress (org.onlab.packet.IpAddress)9 MacAddress (org.onlab.packet.MacAddress)8 ProviderId (org.onosproject.net.provider.ProviderId)6 VlanId (org.onlab.packet.VlanId)4 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)4 HostId (org.onosproject.net.HostId)4 JsonObject (com.eclipsesource.json.JsonObject)3 HashSet (java.util.HashSet)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 Annotations (org.onosproject.net.Annotations)3 DeviceId (org.onosproject.net.DeviceId)2 TestUtils.getIntReportConfig (org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig)2 JsonArray (com.eclipsesource.json.JsonArray)1