Search in sources :

Example 1 with ElementId

use of org.onosproject.net.ElementId in project onos by opennetworkinglab.

the class DefaultTapiResolver method getNodeRef.

@Override
public TapiNodeRef getNodeRef(ElementId deviceId) throws NoSuchElementException {
    updateCache();
    TapiNodeRef ret = null;
    try {
        ret = tapiNodeRefList.stream().filter(node -> node.getDeviceId() != null && node.getDeviceId().equals(deviceId)).findFirst().get();
    } catch (NoSuchElementException e) {
        log.error("Node not found associated with {}", deviceId);
        throw e;
    }
    return ret;
}
Also used : Logger(org.slf4j.Logger) TapiResolver(org.onosproject.odtn.TapiResolver) Deactivate(org.osgi.service.component.annotations.Deactivate) ElementId(org.onosproject.net.ElementId) TapiNodeRef(org.onosproject.odtn.utils.tapi.TapiNodeRef) Collectors(java.util.stream.Collectors) TapiNepRef(org.onosproject.odtn.utils.tapi.TapiNepRef) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Activate(org.osgi.service.component.annotations.Activate) NoSuchElementException(java.util.NoSuchElementException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TapiNodeRef(org.onosproject.odtn.utils.tapi.TapiNodeRef) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with ElementId

use of org.onosproject.net.ElementId in project onos by opennetworkinglab.

the class UiLinkId method canonicalizeIdentifier.

private static UiLinkId canonicalizeIdentifier(ConnectPoint src, ConnectPoint dst) {
    if (src == null || dst == null) {
        throw new NullPointerException("null src or dst connect point (illegal for UiLinkId)");
    }
    ElementId srcId = src.elementId();
    ElementId dstId = dst.elementId();
    // canonicalize
    int comp = srcId.toString().compareTo(dstId.toString());
    return comp <= 0 ? new UiLinkId(srcId, src.port(), dstId, dst.port()) : new UiLinkId(dstId, dst.port(), srcId, src.port());
}
Also used : ElementId(org.onosproject.net.ElementId) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with ElementId

use of org.onosproject.net.ElementId in project onos by opennetworkinglab.

the class MockLinkService method addLink.

public void addLink(String device, long port, String device2, long port2) {
    ElementId d1;
    if (device.charAt(0) == 'H') {
        device = device.substring(1, device.length());
        d1 = HostId.hostId(device);
    } else {
        d1 = DeviceId.deviceId(device);
    }
    ElementId d2;
    if (device2.charAt(0) == 'H') {
        d2 = HostId.hostId(device2.substring(1, device2.length()));
    } else {
        d2 = DeviceId.deviceId(device2);
    }
    ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port));
    ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2));
    Link curLink;
    curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).build();
    links.add(curLink);
    if (d1 instanceof DeviceId && d2 instanceof DeviceId) {
        TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2;
        createdGraph.addVertex(v1);
        createdGraph.addVertex(v2);
        createdGraph.addEdge(new TopologyEdge() {

            @Override
            public Link link() {
                return curLink;
            }

            @Override
            public TopologyVertex src() {
                return v1;
            }

            @Override
            public TopologyVertex dst() {
                return v2;
            }
        });
    }
}
Also used : TopologyVertex(org.onosproject.net.topology.TopologyVertex) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ElementId(org.onosproject.net.ElementId) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link)

Example 4 with ElementId

use of org.onosproject.net.ElementId in project onos by opennetworkinglab.

the class UiLinkId method directionOf.

/**
 * Returns the direction of the given link, or null if this link ID does
 * not correspond to the given link.
 *
 * @param link the link to examine
 * @return corresponding direction
 */
Direction directionOf(Link link) {
    ConnectPoint src = link.src();
    ElementId srcId = src.elementId();
    return elementA.equals(srcId) ? Direction.A_TO_B : elementB.equals(srcId) ? Direction.B_TO_A : null;
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) ElementId(org.onosproject.net.ElementId)

Example 5 with ElementId

use of org.onosproject.net.ElementId in project onos by opennetworkinglab.

the class ConnectPointCodec method decode.

@Override
public ConnectPoint decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    ElementId elementId;
    if (json.has(ELEMENT_DEVICE)) {
        elementId = DeviceId.deviceId(json.get(ELEMENT_DEVICE).asText());
    } else if (json.has(ELEMENT_HOST)) {
        elementId = HostId.hostId(json.get(ELEMENT_HOST).asText());
    } else {
        // invalid JSON
        return null;
    }
    PortNumber portNumber = portNumber(json.get(PORT).asText());
    return new ConnectPoint(elementId, portNumber);
}
Also used : PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) ElementId(org.onosproject.net.ElementId)

Aggregations

ElementId (org.onosproject.net.ElementId)7 ConnectPoint (org.onosproject.net.ConnectPoint)6 PortNumber (org.onosproject.net.PortNumber)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 DefaultLink (org.onosproject.net.DefaultLink)1 DeviceId (org.onosproject.net.DeviceId)1 Link (org.onosproject.net.Link)1 TopologyEdge (org.onosproject.net.topology.TopologyEdge)1 TopologyVertex (org.onosproject.net.topology.TopologyVertex)1 TapiResolver (org.onosproject.odtn.TapiResolver)1 TapiNepRef (org.onosproject.odtn.utils.tapi.TapiNepRef)1 TapiNodeRef (org.onosproject.odtn.utils.tapi.TapiNodeRef)1 Activate (org.osgi.service.component.annotations.Activate)1