org.onosproject.net.host.HostEvent Java Examples

The following examples show how to use org.onosproject.net.host.HostEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: L2BridgingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            // Host added events will be generated by the
            // HostLocationProvider by intercepting ARP/NDP packets.
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts: how to support host moved/removed?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached to.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #2
Source File: AclManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Generate new ACL flow rules for new or updated host following the given ACL rule.
 */
private void processHostAddedEvent(HostEvent event, AclRule rule) {
    DeviceId deviceId = event.subject().location().deviceId();
    for (IpAddress address : event.subject().ipAddresses()) {
        if ((rule.srcIp() != null) ?
                (checkIpInCidr(address.getIp4Address(), rule.srcIp())) :
                (checkIpInCidr(address.getIp4Address(), rule.dstIp()))) {
            if (!aclStore.checkIfRuleWorksInDevice(rule.id(), deviceId)) {
                List<RuleId> allowingRuleList = aclStore
                        .getAllowingRuleByDenyingRule(rule.id());
                if (allowingRuleList != null) {
                    for (RuleId allowingRuleId : allowingRuleList) {
                        generateAclFlow(aclStore.getAclRule(allowingRuleId), deviceId);
                    }
                }
                generateAclFlow(rule, deviceId);
            }
        }
    }
}
 
Example #3
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts:
            // how to support host moved/removed events?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #4
Source File: L2BridgingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            // Host added events will be generated by the
            // HostLocationProvider by intercepting ARP/NDP packets.
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts: how to support host moved/removed?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached to.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #5
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts:
            // how to support host moved/removed events?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #6
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts:
            // how to support host moved/removed events?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #7
Source File: InstancePortManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processHostMove(HostEvent event, InstancePort instPort) {
    Host oldHost = event.prevSubject();
    Host currHost = event.subject();

    // in the middle of VM migration
    if (oldHost.locations().size() < currHost.locations().size()) {
        updateInstancePort(instPort.updateState(MIGRATING));
    }

    // finish of VM migration
    if (oldHost.locations().size() > currHost.locations().size()) {
        Set<HostLocation> diff =
                Sets.difference(oldHost.locations(), currHost.locations());
        HostLocation location = diff.stream().findFirst().orElse(null);

        if (location != null) {
            InstancePort updated = instPort.updateState(MIGRATED);
            updateInstancePort(updated.updatePrevLocation(
                    location.deviceId(), location.port()));
        }
    }
}
 
Example #8
Source File: HostEventConverter.java    From onos with Apache License 2.0 6 votes vote down vote up
private HostNotificationProto buildHostProtoMessage(HostEvent hostEvent) {
    HostNotificationProto.Builder notificationBuilder =
            HostNotificationProto.newBuilder();

    HostProto hostCore =
            HostProto.newBuilder()
                    .setHostId(HostIdProtoTranslator.translate(hostEvent
                            .subject().id()))
                    .setConfigured(hostEvent.subject().configured())
                    .addAllIpAddresses(hostEvent.subject().ipAddresses()
                            .stream().map(IpAddress::toString)
                            .collect(Collectors.toList()))
                    .setLocation(HostLocationProtoTranslator.translate(
                            hostEvent.subject().location()))
                    .setVlan(hostEvent.subject().vlan().toShort())
                    .putAllAnnotations(AnnotationsTranslator.asMap(
                            hostEvent.subject().annotations()))
                    .build();

    notificationBuilder.setHostEventType(getProtoType(hostEvent))
            .setHost(hostCore);

    return notificationBuilder.build();
}
 
Example #9
Source File: VplsManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Adds hosts to a VPLS.
 */
@Test
public void testAddHost() {
    VplsData vplsData  = VplsData.of(VPLS1, NONE);
    vplsData.addInterface(V100H1);
    vplsData.state(ADDED);
    vplsStore.addVpls(vplsData);

    HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, V100HOST1);
    hostService.postHostEvent(hostEvent);

    vplsData = vplsStore.getVpls(VPLS1);
    assertNotNull(vplsData);

    assertEquals(vplsData.state(), UPDATING);
}
 
Example #10
Source File: HostHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testHostProbing() {
    // Case: [1A/1, 1B/1] -> [1A/2, 1B/1]
    // Expect: DISCOVER probe should be sent to every port on 1B that has the same VLAN as 1A/2
    //         VERIFY probe should be sent to 1B/1
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));

    hostHandler.srManager.probingService = createMock(HostProbingService.class);
    hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.DISCOVER);
    expectLastCall();
    hostHandler.srManager.probingService.probeHost(host2, CP42, ProbeMode.DISCOVER);
    expectLastCall();
    hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.VERIFY);
    expectLastCall();
    replay(hostHandler.srManager.probingService);

    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));

    verify(hostHandler.srManager.probingService);
}
 
Example #11
Source File: HostHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testDualHomedHostMoveTransient() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));

    // Mock DefaultRoutingHandler
    DefaultRoutingHandler mockDefaultRoutingHandler = createMock(DefaultRoutingHandler.class);
    hostHandler.srManager.defaultRoutingHandler = mockDefaultRoutingHandler;

    // Host moved from [1A/1, 1B/1] to [1A/2, 1B/1]
    // We should expect only one bridging flow and one routing flow programmed on 1A

    expect(mockDefaultRoutingHandler.populateBridging(DEV3, P2, HOST_MAC, HOST_VLAN_UNTAGGED))
            .andReturn(CompletableFuture.completedFuture(null)).once();
    expect(mockDefaultRoutingHandler.populateRoute(DEV3, HOST_IP11.toIpPrefix(),
            HOST_MAC, HOST_VLAN_UNTAGGED, P2, true))
            .andReturn(CompletableFuture.completedFuture(null)).once();
    replay(mockDefaultRoutingHandler);

    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
    verify(mockDefaultRoutingHandler);
}
 
Example #12
Source File: HostHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testDualHomedHostRemoved() {
    // Add a dual-homed host that has 2 locations
    // Expect: add two routing rules and two bridging rules
    Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(2, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
    assertEquals(2, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));

    // Remove a dual-homed host that has 2 locations
    // Expect: all routing and bridging rules are removed
    hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());
}
 
Example #13
Source File: HostHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testHostRemoved() {
    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)));

    // 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());
}
 
Example #14
Source File: L2BridgingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    switch (event.type()) {
        case HOST_ADDED:
            // Host added events will be generated by the
            // HostLocationProvider by intercepting ARP/NDP packets.
            break;
        case HOST_REMOVED:
        case HOST_UPDATED:
        case HOST_MOVED:
        default:
            // Ignore other events.
            // Food for thoughts: how to support host moved/removed?
            return false;
    }
    // Process host event only if this controller instance is the master
    // for the device where this host is attached to.
    final Host host = event.subject();
    final DeviceId deviceId = host.location().deviceId();
    return mastershipService.isLocalMaster(deviceId);
}
 
Example #15
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleHomedHostAddedOnPairLeaf() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC33), Sets.newHashSet(HOST_IP33), false);

    // Add a single-homed host with one location
    // Expect: the pair link should not be utilized
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertEquals(P3, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP33.toIpPrefix())).portNumber);
    assertEquals(1, BRIDGING_TABLE.size());
    assertEquals(P3, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_OTHER)).portNumber);
}
 
Example #16
Source File: HostManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Activate
public void activate(ComponentContext context) {
    hostAnnotationOperator = new HostAnnotationOperator(networkConfigService);
    store.setDelegate(delegate);
    eventDispatcher.addSink(HostEvent.class, listenerRegistry);
    cfgService.registerProperties(getClass());
    networkConfigService.addListener(networkConfigListener);
    monitor = new HostMonitor(packetService, this, interfaceService, edgePortService);
    monitor.setProbeRate(probeRate);
    monitor.start();
    cfgService.registerProperties(getClass());
    modified(context);
    log.info("Started");
}
 
Example #17
Source File: DistributedHostStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public HostEvent removeIp(HostId hostId, IpAddress ipAddress) {
    hosts.compute(hostId, (id, existingHost) -> {
        if (existingHost != null) {
            checkState(Objects.equals(hostId.mac(), existingHost.mac()),
                    "Existing and new MAC addresses differ.");
            checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()),
                    "Existing and new VLANs differ.");

            Set<IpAddress> addresses = existingHost.ipAddresses();
            if (addresses != null && addresses.contains(ipAddress)) {
                addresses = new HashSet<>(existingHost.ipAddresses());
                addresses.remove(ipAddress);
                removeIpFromHostsByIp(existingHost, ipAddress);
                return new DefaultHost(existingHost.providerId(),
                        hostId,
                        existingHost.mac(),
                        existingHost.vlan(),
                        existingHost.locations(),
                        existingHost.auxLocations(),
                        ImmutableSet.copyOf(addresses),
                        existingHost.innerVlan(),
                        existingHost.tpid(),
                        existingHost.configured(),
                        existingHost.suspended(),
                        existingHost.annotations());
            } else {
                return existingHost;
            }
        }
        return null;
    });
    return null;
}
 
Example #18
Source File: DistributedHostStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostAuxMoved() {
    // Host aux location changed
    MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
            new Versioned<>(HOST4, 1), new Versioned<>(HOST1, 0));
    // Expect: HOST_AUX_MOVED
    ecXHostStore.hostLocationTracker.event(event);
    assertEquals(HostEvent.Type.HOST_AUX_MOVED, delegate.lastEvent.type());
    assertEquals(HOST4, delegate.lastEvent.subject());
    assertEquals(HOST1, delegate.lastEvent.prevSubject());
}
 
Example #19
Source File: DistributedHostStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostAdded() {
    // Host is first discovered at only one location
    MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
            new Versioned<>(HOST1, 0), null);
    // Expect: HOST_ADDED
    ecXHostStore.hostLocationTracker.event(event);
    assertEquals(HostEvent.Type.HOST_ADDED, delegate.lastEvent.type());
    assertEquals(HOST1, delegate.lastEvent.subject());
    assertNull(delegate.lastEvent.prevSubject());
}
 
Example #20
Source File: DistributedHostStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostUpdated() {
    // Host is updated with an IP
    MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
            new Versioned<>(HOST2, 1), new Versioned<>(HOST1, 0));
    // Expect: HOST_UPDATED
    ecXHostStore.hostLocationTracker.event(event);
    assertEquals(HostEvent.Type.HOST_UPDATED, delegate.lastEvent.type());
    assertEquals(HOST2, delegate.lastEvent.subject());
    assertEquals(HOST1, delegate.lastEvent.prevSubject());
}
 
Example #21
Source File: DistributedHostStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostMoved() {
    // Host is updated with a second location
    MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
            new Versioned<>(HOST3, 1), new Versioned<>(HOST2, 0));
    // Expect: HOST_MOVED
    ecXHostStore.hostLocationTracker.event(event);
    assertEquals(HostEvent.Type.HOST_MOVED, delegate.lastEvent.type());
    assertEquals(HOST3, delegate.lastEvent.subject());
    assertEquals(HOST2, delegate.lastEvent.prevSubject());
}
 
Example #22
Source File: SimpleHostStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public HostEvent removeHost(HostId hostId) {
    synchronized (this) {
        Host host = hosts.remove(hostId);
        if (host != null) {
            locations.remove((host.location()), host);
            HostEvent hostEvent = new HostEvent(HOST_REMOVED, host);
            notifyDelegate(hostEvent);
            return hostEvent;
        }
        return null;
    }
}
 
Example #23
Source File: RouteHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualHomedSingleLocationFail() {
    testOneDualHomedAdded();

    ROUTE_STORE.put(P1, Sets.newHashSet(RR3));

    reset(srManager.deviceConfiguration);
    expect(srManager.deviceConfiguration.getBatchedSubnets(H3D.id()))
            .andReturn(Lists.<Set<IpPrefix>>newArrayList(Sets.newHashSet(P1)));
    srManager.deviceConfiguration.removeSubnet(CP2, P1);
    expectLastCall().once();
    replay(srManager.deviceConfiguration);

    HostEvent he = new HostEvent(HostEvent.Type.HOST_MOVED, H3S, H3D);
    routeHandler.processHostMovedEvent(he);

    // We do not remove the route on CP2. Instead, we let the subnet population overrides it
    assertEquals(2, ROUTING_TABLE.size());
    MockRoutingTableValue rtv1 = ROUTING_TABLE.get(new MockRoutingTableKey(CP1.deviceId(), P1));
    assertEquals(M3, rtv1.macAddress);
    assertEquals(V3, rtv1.vlanId);
    assertEquals(CP1.port(), rtv1.portNumber);

    // ECMP route table hasn't changed
    assertEquals(1, SUBNET_TABLE.size());
    assertTrue(SUBNET_TABLE.get(CP1).contains(P1));

    verify(srManager.deviceConfiguration);
}
 
Example #24
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelayedIpAndLocation2() {
    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, HOST_LOC41), Sets.newHashSet(), 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 Location
    // Expect: cancel bridging redirections
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, 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(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);

    // Discover IP
    // Expect: add IP rules to both location
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, 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);
}
 
Example #25
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostUpdated() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP21), false);
    Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP12), false);

    // Add a host
    // Expect: add one new routing rule. Add one new bridging rule.
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(HOST_LOC11.deviceId(), HOST_MAC,
            INTF_VLAN_UNTAGGED)));

    // Update the host IP to same subnet
    // Expect: update routing rule with new IP. No change to bridging rule.
    hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));

    // Update the host IP to different subnet
    // Expect: Remove routing rule. No change to bridging rule.
    hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
}
 
Example #26
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #27
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostMoveToInvalidLocation() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP11), false);

    // Add a host
    // Expect: add one new routing rule, one new bridging rule
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));

    // Move the host to an invalid location
    // Expect: Old flow is removed. New flow is not created
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());

    // Move the host to a valid location
    // Expect: add one new routing rule, one new bridging rule
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
}
 
Example #28
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostMoved() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
    Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP11), false);

    // Add a host
    // Expect: add one new routing rule, one new bridging rule
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));

    // Move the host to CP13, which has different subnet setting
    // Expect: remove routing rule. Change vlan in bridging rule.
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host1));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
    assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));

    // Move the host to CP21, which has same subnet setting
    // Expect: add a new routing rule. Change vlan in bridging rule.
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
    assertEquals(1, ROUTING_TABLE.size());
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
}
 
Example #29
Source File: HostHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testDualHomedHostAddedOneByOne() {
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
            Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
    Host host2 = 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-homed host with one location
    // Expect: the pair link is utilized temporarily before the second location is discovered
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, 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(host1, CP41, ProbeMode.DISCOVER));

    // Add the second location of dual-homed host
    // Expect: no longer use the pair link
    hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
    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);
}
 
Example #30
Source File: RouteHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleHomedToDualHomed() {
    testDualHomedSingleLocationFail();

    reset(srManager.deviceConfiguration);
    expect(srManager.deviceConfiguration.getBatchedSubnets(H3S.id()))
            .andReturn(Lists.<Set<IpPrefix>>newArrayList(Sets.newHashSet(P1)));
    srManager.deviceConfiguration.addSubnet(CP2, P1);
    expectLastCall().once();
    replay(srManager.deviceConfiguration);

    HostEvent he = new HostEvent(HostEvent.Type.HOST_MOVED, H3D, H3S);
    routeHandler.processHostMovedEvent(he);

    assertEquals(2, ROUTING_TABLE.size());
    MockRoutingTableValue rtv1 = ROUTING_TABLE.get(new MockRoutingTableKey(CP1.deviceId(), P1));
    MockRoutingTableValue rtv2 = ROUTING_TABLE.get(new MockRoutingTableKey(CP2.deviceId(), P1));
    assertEquals(M3, rtv1.macAddress);
    assertEquals(M3, rtv2.macAddress);
    assertEquals(V3, rtv1.vlanId);
    assertEquals(V3, rtv2.vlanId);
    assertEquals(CP1.port(), rtv1.portNumber);
    assertEquals(CP2.port(), rtv2.portNumber);

    assertEquals(2, SUBNET_TABLE.size());
    assertTrue(SUBNET_TABLE.get(CP1).contains(P1));
    assertTrue(SUBNET_TABLE.get(CP2).contains(P1));

    verify(srManager.deviceConfiguration);
}