Java Code Examples for org.onosproject.net.host.HostEvent#subject()

The following examples show how to use org.onosproject.net.host.HostEvent#subject() . 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 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 2
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 3
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 4
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 5
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 6
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 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: TopologyViewMessageHandlerBase.java    From onos with Apache License 2.0 5 votes vote down vote up
protected ObjectNode hostMessage(HostEvent event) {
    Host host = event.subject();
    Host prevHost = event.prevSubject();
    String hostType = host.annotations().value(AnnotationKeys.UI_TYPE);
    String ip = ip(host.ipAddresses());

    ObjectNode payload = objectNode()
            .put("id", host.id().toString())
            .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType);

    // set most recent connect point (and previous if we know it)
    payload.set("cp", hostConnect(host.location()));
    if (prevHost != null && prevHost.location() != null) {
        payload.set("prevCp", hostConnect(prevHost.location()));
    }

    // set ALL connect points
    addAllCps(host.locations(), payload);

    payload.set("labels", labels(nameForHost(host), ip, host.mac().toString(), ""));
    payload.set("props", props(host.annotations()));

    BasicHostConfig cfg = get(NetworkConfigService.class)
            .getConfig(host.id(), BasicHostConfig.class);
    if (!addLocation(cfg, payload)) {
        addMetaUi(host.id().toString(), payload);
    }

    String type = HOST_EVENT.get(event.type());
    return JsonUtils.envelope(type, payload);
}
 
Example 9
Source File: OpenstackVtapManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    Host host = event.subject();
    if (!isValidHost(host)) {
        log.debug("Invalid host detected, ignore it {}", host);
        return false;
    }

    // do not allow to proceed without leadership
    NodeId leader = leadershipService.getLeader(appId.name());
    return Objects.equals(localNodeId, leader);
}
 
Example 10
Source File: InstancePortManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRelevant(HostEvent event) {
    Host host = event.subject();
    if (!isValidHost(host)) {
        log.debug("Invalid host detected, ignore it {}", host);
        return false;
    }

    // do not allow to proceed without leadership
    NodeId leader = leadershipService.getLeader(appId.name());
    return Objects.equals(localNodeId, leader);
}
 
Example 11
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
void processHostAddedEvent(HostEvent event) {
    Host host = event.subject();
    hostWorkers.execute(() -> processHostAdded(host), host.id().hashCode());
}
 
Example 12
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
void processHostRemovedEvent(HostEvent event) {
    Host host = event.subject();
    hostWorkers.execute(() -> processHostRemoved(host), host.id().hashCode());
}
 
Example 13
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
void processHostMovedEvent(HostEvent event) {
    Host host = event.subject();
    hostWorkers.execute(() -> processHostMovedEventInternal(event), host.id().hashCode());
}
 
Example 14
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
void processHostUpdatedEvent(HostEvent event) {
    Host host = event.subject();
    hostWorkers.execute(() -> processHostUpdatedEventInternal(event), host.id().hashCode());
}
 
Example 15
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processHostUpdatedEventInternal(HostEvent event) {
    Host host = event.subject();
    MacAddress hostMac = host.mac();
    VlanId hostVlanId = host.vlan();
    EthType hostTpid = host.tpid();
    Set<HostLocation> locations = effectiveLocations(host);
    Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
    Set<IpAddress> newIps = host.ipAddresses();
    log.info("Host {}/{} is updated", hostMac, hostVlanId);

    locations.forEach(location -> {
        Sets.difference(prevIps, newIps).forEach(ip -> {
            if (isDoubleTaggedHost(host)) {
                processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac,
                                               host.innerVlan(), hostVlanId, hostTpid, ip, true);
            } else {
                processRoutingRule(location.deviceId(), location.port(), hostMac,
                                   hostVlanId, ip, true);
            }
        });
        Sets.difference(newIps, prevIps).forEach(ip -> {
            if (isDoubleTaggedHost(host)) {
                processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac,
                                               host.innerVlan(), hostVlanId, hostTpid, ip, false);
            } else {
                processRoutingRule(location.deviceId(), location.port(), hostMac,
                                   hostVlanId, ip, false);
            }
        });
    });

    // Use the pair link temporarily before the second location of a dual-homed host shows up.
    // This do not affect single-homed hosts since the flow will be blocked in
    // processBridgingRule or processRoutingRule due to VLAN or IP mismatch respectively
    locations.forEach(location ->
        srManager.getPairDeviceId(location.deviceId()).ifPresent(pairDeviceId -> {
            if (locations.stream().noneMatch(l -> l.deviceId().equals(pairDeviceId))) {
                Set<IpAddress> ipsToAdd = Sets.difference(newIps, prevIps);
                Set<IpAddress> ipsToRemove = Sets.difference(prevIps, newIps);

                srManager.getPairLocalPort(pairDeviceId).ifPresent(pairRemotePort -> {
                    // NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
                    //       when the host is untagged
                    VlanId vlanId = vlanForPairPort(hostVlanId, location);
                    if (vlanId == null) {
                        return;
                    }

                    ipsToRemove.forEach(ip ->
                            processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, true)
                    );
                    ipsToAdd.forEach(ip ->
                            processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, false)
                    );

                    if (srManager.activeProbing) {
                        probe(host, location, pairDeviceId, pairRemotePort);
                    }
                });
            }
        })
    );
}