Search in sources :

Example 31 with Annotations

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

the class DefaultPortSerializer method read.

@Override
public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) {
    Element element = (Element) kryo.readClassAndObject(input);
    PortNumber number = kryo.readObject(input, PortNumber.class);
    boolean isEnabled = input.readBoolean();
    Port.Type type = kryo.readObject(input, Port.Type.class);
    long portSpeed = input.readLong();
    Annotations annotations = (Annotations) kryo.readClassAndObject(input);
    return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations);
}
Also used : Annotations(org.onosproject.net.Annotations) Element(org.onosproject.net.Element) DefaultPort(org.onosproject.net.DefaultPort) Port(org.onosproject.net.Port) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort)

Example 32 with Annotations

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

the class RegionCodecTest method testRegionEncode.

/**
 * Tests encoding of a Region object.
 */
@Test
public void testRegionEncode() {
    NodeId nodeId1 = NodeId.nodeId("1");
    NodeId nodeId2 = NodeId.nodeId("2");
    NodeId nodeId3 = NodeId.nodeId("3");
    NodeId nodeId4 = NodeId.nodeId("4");
    Set<NodeId> set1 = ImmutableSet.of(nodeId1);
    Set<NodeId> set2 = ImmutableSet.of(nodeId1, nodeId2);
    Set<NodeId> set3 = ImmutableSet.of(nodeId1, nodeId2, nodeId3);
    Set<NodeId> set4 = ImmutableSet.of(nodeId1, nodeId2, nodeId3, nodeId4);
    List<Set<NodeId>> masters = ImmutableList.of(set1, set2, set3, set4);
    RegionId regionId = RegionId.regionId("1");
    String name = "foo";
    Region.Type type = Region.Type.ROOM;
    Annotations noAnnots = DefaultAnnotations.EMPTY;
    Region region = new DefaultRegion(regionId, name, type, noAnnots, masters);
    ObjectNode regionJson = regionCodec.encode(region, context);
    assertThat(regionJson, matchesRegion(region));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NodeId(org.onosproject.cluster.NodeId) Region(org.onosproject.net.region.Region) RegionJsonMatcher.matchesRegion(org.onosproject.codec.impl.RegionJsonMatcher.matchesRegion) DefaultRegion(org.onosproject.net.region.DefaultRegion) DefaultRegion(org.onosproject.net.region.DefaultRegion) RegionId(org.onosproject.net.region.RegionId) Test(org.junit.Test)

Example 33 with Annotations

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

the class OplinkHandshakerUtil method buildPortAdjacencyDescriptions.

/**
 * Creates port descriptions with adjacency.
 *
 * @param portAds adjacency information
 * @return port descriptions
 */
public List<PortDescription> buildPortAdjacencyDescriptions(List<OFExpPortAdjacency> portAds) {
    DeviceService deviceService = driver.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(driver.data().deviceId());
    // Map port's number with port's adjacency
    HashMap<Long, OFExpPortAdjacency> adMap = new HashMap<>(portAds.size());
    portAds.forEach(ad -> adMap.put((long) ad.getPortNo().getPortNumber(), ad));
    List<PortDescription> portDescs = new ArrayList<>();
    for (Port port : ports) {
        DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
        Annotations oldAnnotations = port.annotations();
        builder.putAll(oldAnnotations);
        OFExpPortAdjacency ad = adMap.get(port.number().toLong());
        OplinkPortAdjacency neighbor = getNeighbor(ad);
        if (!linkValidation(deviceService, neighbor)) {
            // no neighbors found
            builder.remove(OpticalAnnotations.NEIGHBOR_ID);
            builder.remove(OpticalAnnotations.NEIGHBOR_PORT);
            removeLink(port.number());
        } else {
            // neighbor discovered, add to port descriptions
            String newId = neighbor.getDeviceId().toString();
            String newPort = neighbor.getPort().toString();
            // Check if annotation already exists
            if (!newId.equals(oldAnnotations.value(OpticalAnnotations.NEIGHBOR_ID)) || !newPort.equals(oldAnnotations.value(OpticalAnnotations.NEIGHBOR_PORT))) {
                builder.set(OpticalAnnotations.NEIGHBOR_ID, newId);
                builder.set(OpticalAnnotations.NEIGHBOR_PORT, newPort);
            }
            addLink(port.number(), neighbor);
        }
        portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
    }
    return portDescs;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HashMap(java.util.HashMap) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) OpticalAnnotations(org.onosproject.net.optical.OpticalAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) OFExpPortAdjacency(org.projectfloodlight.openflow.protocol.OFExpPortAdjacency)

Example 34 with Annotations

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

the class DefaultOpenstackNode method macAddress.

private MacAddress macAddress(DeviceId deviceId, String portName) {
    Port port = port(deviceId, portName);
    Annotations annots = port.annotations();
    return annots != null ? MacAddress.valueOf(annots.value(PORT_MAC)) : null;
}
Also used : Annotations(org.onosproject.net.Annotations) Port(org.onosproject.net.Port)

Example 35 with Annotations

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

the class OmsPortHelper method asOmsPort.

public static Optional<OmsPort> asOmsPort(Port port) {
    if (port instanceof OmsPort) {
        return Optional.of((OmsPort) port);
    }
    try {
        Annotations an = port.annotations();
        Frequency minFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MIN_FREQ_HZ)));
        Frequency maxFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MAX_FREQ_HZ)));
        Frequency grid = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.GRID_HZ)));
        return Optional.of(new DefaultOmsPort(port, minFrequency, maxFrequency, grid));
    } catch (NumberFormatException e) {
        log.warn("{} was not well-formed OMS port.", port, e);
        return Optional.empty();
    }
}
Also used : DefaultOmsPort(org.onosproject.net.optical.impl.DefaultOmsPort) OmsPort(org.onosproject.net.optical.OmsPort) OpticalAnnotations(org.onosproject.net.optical.OpticalAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) Frequency(org.onlab.util.Frequency) DefaultOmsPort(org.onosproject.net.optical.impl.DefaultOmsPort)

Aggregations

Annotations (org.onosproject.net.Annotations)39 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 Test (org.junit.Test)9 Device (org.onosproject.net.Device)9 Port (org.onosproject.net.Port)8 ArrayList (java.util.ArrayList)6 DefaultDevice (org.onosproject.net.DefaultDevice)6 DefaultPort (org.onosproject.net.DefaultPort)6 SparseAnnotations (org.onosproject.net.SparseAnnotations)5 IpAddress (org.onlab.packet.IpAddress)4 DefaultPath (org.onosproject.net.DefaultPath)4 PortNumber (org.onosproject.net.PortNumber)4 ProviderId (org.onosproject.net.provider.ProviderId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Set (java.util.Set)3 Before (org.junit.Before)3 Frequency (org.onlab.util.Frequency)3 NodeId (org.onosproject.cluster.NodeId)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultHost (org.onosproject.net.DefaultHost)3