Search in sources :

Example 6 with Type

use of org.onosproject.net.Link.Type in project onos by opennetworkinglab.

the class EdgeManager method processDeviceEvent.

// Processes a device event by adding or removing its end-points in our cache.
private void processDeviceEvent(DeviceEvent event) {
    // FIXME handle the case where a device is suspended, this may or may not come up
    DeviceEvent.Type type = event.type();
    DeviceId id = event.subject().id();
    if (type == DEVICE_ADDED || type == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(id)) {
        // When device is added or becomes available, add all its ports
        deviceService.getPorts(event.subject().id()).forEach(p -> addEdgePort(new ConnectPoint(id, p.number())));
    } else if (type == DEVICE_REMOVED || type == DEVICE_AVAILABILITY_CHANGED && !deviceService.isAvailable(id)) {
        // When device is removed or becomes unavailable, remove all its ports.
        // Note: cannot rely on Device subsystem, ports may be gone.
        Optional.ofNullable(connectionPoints.remove(id)).orElse(ImmutableSet.of()).forEach(point -> post(new EdgePortEvent(EDGE_PORT_REMOVED, point)));
    } else if (type == DeviceEvent.Type.PORT_ADDED || type == PORT_UPDATED && event.port().isEnabled()) {
        addEdgePort(new ConnectPoint(id, event.port().number()));
    } else if (type == DeviceEvent.Type.PORT_REMOVED || type == PORT_UPDATED && !event.port().isEnabled()) {
        removeEdgePort(new ConnectPoint(id, event.port().number()));
    }
}
Also used : PACKET_WRITE(org.onosproject.security.AppPermission.Type.PACKET_WRITE) EdgePortEvent(org.onosproject.net.edge.EdgePortEvent) LinkEvent(org.onosproject.net.link.LinkEvent) DEVICE_ADDED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED) DeviceService(org.onosproject.net.device.DeviceService) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) DEVICE_REMOVED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Component(org.osgi.service.component.annotations.Component) OutboundPacket(org.onosproject.net.packet.OutboundPacket) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) EdgePortService(org.onosproject.net.edge.EdgePortService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PORT_STATS_UPDATED(org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED) EDGE_PORT_ADDED(org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED) EDGE_PORT_REMOVED(org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED) DeviceListener(org.onosproject.net.device.DeviceListener) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LinkListener(org.onosproject.net.link.LinkListener) EdgePortListener(org.onosproject.net.edge.EdgePortListener) DeviceEvent(org.onosproject.net.device.DeviceEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) PORT_UPDATED(org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED) TOPOLOGY_READ(org.onosproject.security.AppPermission.Type.TOPOLOGY_READ) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DEVICE_AVAILABILITY_CHANGED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) Type(org.onosproject.net.Link.Type) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) EdgePortEvent(org.onosproject.net.edge.EdgePortEvent) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 7 with Type

use of org.onosproject.net.Link.Type in project onos by opennetworkinglab.

the class LinkCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Link decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class);
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId("json", "LinkCodec");
    ConnectPoint src = codec.decode(get(json, SRC), context);
    ConnectPoint dst = codec.decode(get(json, DST), context);
    Type type = Type.valueOf(json.get(TYPE).asText());
    Annotations annotations = extractAnnotations(json, context);
    return DefaultLink.builder().providerId(pid).src(src).dst(dst).type(type).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) Annotations(org.onosproject.net.Annotations) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 8 with Type

use of org.onosproject.net.Link.Type in project onos by opennetworkinglab.

the class SimpleLinkStore method createOrUpdateLinkDescription.

// Guarded by linkDescs value (=locking each Link)
private LinkDescription createOrUpdateLinkDescription(Map<ProviderId, LinkDescription> descs, ProviderId providerId, LinkDescription linkDescription) {
    // merge existing attributes and merge
    LinkDescription oldDesc = descs.get(providerId);
    LinkDescription newDesc = linkDescription;
    if (oldDesc != null) {
        // we only allow transition from INDIRECT -> DIRECT
        final Type newType;
        if (oldDesc.type() == DIRECT) {
            newType = DIRECT;
        } else {
            newType = linkDescription.type();
        }
        SparseAnnotations merged = union(oldDesc.annotations(), linkDescription.annotations());
        newDesc = new DefaultLinkDescription(linkDescription.src(), linkDescription.dst(), newType, merged);
    }
    return descs.put(providerId, newDesc);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Type(org.onosproject.net.Link.Type) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Aggregations

Type (org.onosproject.net.Link.Type)8 ConnectPoint (org.onosproject.net.ConnectPoint)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)5 LinkDescription (org.onosproject.net.link.LinkDescription)5 DeviceId (org.onosproject.net.DeviceId)4 ProviderId (org.onosproject.net.provider.ProviderId)4 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 Map (java.util.Map)2 Set (java.util.Set)2 ONOSLLDP (org.onlab.packet.ONOSLLDP)2 PortNumber (org.onosproject.net.PortNumber)2 LinkEvent (org.onosproject.net.link.LinkEvent)2 Activate (org.osgi.service.component.annotations.Activate)2 Component (org.osgi.service.component.annotations.Component)2 Deactivate (org.osgi.service.component.annotations.Deactivate)2 Reference (org.osgi.service.component.annotations.Reference)2 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)2 Logger (org.slf4j.Logger)2