Search in sources :

Example 21 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 22 with Annotations

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

the class MeteredConstraintTest method setUp.

@Before
public void setUp() {
    resourceContext = createMock(ResourceContext.class);
    Annotations annotations1 = DefaultAnnotations.builder().set(METERED, METERED1).build();
    Annotations annotations2 = DefaultAnnotations.builder().set(METERED, METERED2).build();
    meteredLink = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).annotations(annotations1).build();
    nonMeteredLink = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).annotations(annotations2).build();
    unAnnotatedLink = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN5)).dst(cp(DID3, PN6)).type(DIRECT).build();
    meteredPath = new DefaultPath(PROVIDER_ID, Arrays.asList(meteredLink, nonMeteredLink), ScalarWeight.toWeight(10));
    nonMeteredPath = new DefaultPath(PROVIDER_ID, Arrays.asList(nonMeteredLink, unAnnotatedLink), ScalarWeight.toWeight(10));
}
Also used : ResourceContext(org.onosproject.net.intent.ResourceContext) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 23 with Annotations

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

the class TierConstraintTest method setUp.

@Before
public void setUp() {
    resourceContext = createMock(ResourceContext.class);
    Annotations annotations1 = DefaultAnnotations.builder().set(TIER, TIER1).build();
    Annotations annotations2 = DefaultAnnotations.builder().set(TIER, TIER2).build();
    Annotations annotations3 = DefaultAnnotations.builder().set(TIER, TIER3).build();
    link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).annotations(annotations1).build();
    link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).annotations(annotations2).build();
    link3 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN5)).dst(cp(DID4, PN6)).type(DIRECT).annotations(annotations3).build();
    path12 = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
    path13 = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link3), ScalarWeight.toWeight(10));
    path23 = new DefaultPath(PROVIDER_ID, Arrays.asList(link2, link3), ScalarWeight.toWeight(10));
}
Also used : ResourceContext(org.onosproject.net.intent.ResourceContext) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 24 with Annotations

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

the class HostServiceAdapter method getHost.

@Override
public Host getHost(HostId hostId) {
    ProviderId providerId = ProviderId.NONE;
    MacAddress mac = MacAddress.valueOf("fa:12:3e:56:ee:a2");
    VlanId vlan = VlanId.NONE;
    HostLocation location = HostLocation.NONE;
    Set<IpAddress> ips = Sets.newHashSet();
    Annotations annotations = null;
    return new DefaultHost(providerId, hostId, mac, vlan, location, ips, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) Annotations(org.onosproject.net.Annotations) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId)

Example 25 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)

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