Java Code Examples for org.onosproject.net.link.LinkEvent#subject()

The following examples show how to use org.onosproject.net.link.LinkEvent#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: TopologyHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isValid(LinkEvent linkEvent) {
    Link link = linkEvent.subject();
    // Verify if the link is valid with the link handler
    if (!srManager.linkHandler.isLinkValid(link)) {
        log.debug("Link {} ignored by the LinkHandler", link);
        return false;
    }
    // Processing for LINK_REMOVED
    if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
        // device availability check helps to ensure that multiple link-removed
        // events are actually treated as a single switch removed event.
        // purgeSeenLink is necessary so we do rerouting (instead of rehashing)
        // when switch comes back.
        if (link.src().elementId() instanceof DeviceId
                && !srManager.deviceService.isAvailable(link.src().deviceId())) {
            log.debug("Link {} ignored device {} is down", link, link.src().deviceId());
            return false;
        }
        if (link.dst().elementId() instanceof DeviceId
                && !srManager.deviceService.isAvailable(link.dst().deviceId())) {
            log.debug("Link {} ignored device {} is down", link, link.dst().deviceId());
            return false;
        }
        // LINK_REMOVED is ok
        return true;
    }
    // Processing for LINK_ADDED and LINK_UPDATED
    // Verify if source device is configured
    if (srManager.deviceConfiguration == null ||
            !srManager.deviceConfiguration.isConfigured(link.src().deviceId())) {
        // Source device is not configured, not valid for us
        log.warn("Source device of this link is not configured.. "
                         + "not processing further");
        return false;
    }
    // LINK_ADDED/LINK_UPDATED is ok
    return true;
}
 
Example 2
Source File: MQUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a JSON representation of the given link event.
 *
 * @param  event the link event
 * @return       the link event json message
 */
public static JsonObject json(LinkEvent event) {
    Link link = event.subject();
    JsonObject jo = new JsonObject();
    jo.addProperty(EVENT_TYPE, event.type().name());
    jo.addProperty(DEST, link.dst().deviceId().toString());
    jo.addProperty(SRC, link.src().deviceId().toString());
    jo.addProperty(EXPECTED, link.isExpected());
    jo.addProperty(STATE, link.state().name());
    jo.addProperty(LINK_TYPE, link.type().name());
    return jo;
}
 
Example 3
Source File: PceWebTopovOverlay.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> additionalLinkData(LinkEvent event) {
    Map<String, String> map = new HashMap<>();
    Link link = event.subject();
    long srcPortNo;
    long dstPortNo;
    IpAddress ipDstAddress = null;
    IpAddress ipSrcAddress = null;
    String srcPort;
    String dstPort;
    String bandWidth;

    srcPortNo = link.src().port().toLong();
    if (((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
        srcPort = String.valueOf(srcPortNo);
    } else {
        ipSrcAddress = Ip4Address.valueOf((int) srcPortNo);
        srcPort = ipSrcAddress.toString();
    }

    dstPortNo = link.dst().port().toLong();
    if (((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
        dstPort = String.valueOf(dstPortNo);
    } else {
        ipDstAddress = Ip4Address.valueOf((int) dstPortNo);
        dstPort = ipDstAddress.toString();
    }

    map.put("Src Address", srcPort);
    map.put("Dst Address", dstPort);
    map.put("Te metric", link.annotations().value(TE_METRIC));

    ResourceService resService = AbstractShellCommand.get(ResourceService.class);
    DiscreteResource devResource = Resources.discrete(link.src().deviceId(), link.src().port()).resource();
    if (resService == null) {
        log.warn("resource service does not exist");
        return map;
    }

    if (devResource == null) {
        log.warn("Device resources does not exist");
        return map;
    }
    double regBandwidth = 0;
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        log.error("Exception occurred while getting the bandwidth.");
        Thread.currentThread().interrupt();
    }
    Set<Resource> resources = resService.getRegisteredResources(devResource.id());
    for (Resource res : resources) {
        if (res instanceof ContinuousResource) {
            regBandwidth = ((ContinuousResource) res).value();
            break;
        }
    }

    if (regBandwidth != 0) {
        bandWidth = String.valueOf(regBandwidth);
        map.put("Bandwidth", bandWidth);
    }

    return map;
}
 
Example 4
Source File: EventsCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
        DeviceEvent deviceEvent = (DeviceEvent) event;
        if (event.type().toString().startsWith("PORT")) {
            // Port event
            print("%s %s\t%s/%s [%s]",
                  Tools.defaultOffsetDataTime(event.time()),
                  event.type(),
                  deviceEvent.subject().id(), deviceEvent.port().number(),
                  deviceEvent.port()
              );
        } else {
            // Device event
            print("%s %s\t%s [%s]",
                  Tools.defaultOffsetDataTime(event.time()),
                  event.type(),
                  deviceEvent.subject().id(),
                  deviceEvent.subject()
              );
        }

    } else if (event instanceof MastershipEvent) {
        print("%s %s\t%s [%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              event.subject(),
              ((MastershipEvent) event).roleInfo());

    } else if (event instanceof LinkEvent) {
        LinkEvent linkEvent = (LinkEvent) event;
        Link link = linkEvent.subject();
        print("%s %s\t%s/%s-%s/%s [%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(),
              link);

    } else if (event instanceof HostEvent) {
        HostEvent hostEvent = (HostEvent) event;
        print("%s %s\t%s [%s->%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              hostEvent.subject().id(),
              hostEvent.prevSubject(), hostEvent.subject());

    } else if (event instanceof TopologyEvent) {
        TopologyEvent topoEvent = (TopologyEvent) event;
        List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(),
                                                       ImmutableList.<Event>of());
        Topology topo = topoEvent.subject();
        String summary = String.format("(d=%d,l=%d,c=%d)",
                                       topo.deviceCount(),
                                       topo.linkCount(),
                                       topo.clusterCount());
        print("%s %s%s [%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              summary,
              reasons.stream().map(e -> e.type()).collect(toList()));

    } else if (event instanceof ClusterEvent) {
        print("%s %s\t%s [%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              ((ClusterEvent) event).subject().id(),
              event.subject());

    } else {
        // Unknown Event?
        print("%s %s\t%s [%s]",
              Tools.defaultOffsetDataTime(event.time()),
              event.type(),
              event.subject(),
              event);
    }
}