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