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;
}
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));
}
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));
}
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);
}
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));
}
Aggregations