use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class LinkDiscoveryCiscoImpl method findDestinationPortByName.
private Port findDestinationPortByName(String remotePortName, String remotePortDesc, DeviceService deviceService, Device remoteDevice) {
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(PORT_NAME))).findAny();
if (remotePort.isPresent()) {
return remotePort.get();
} else {
Optional<Port> remotePortByDesc = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortDesc.equals(port.annotations().value(PORT_NAME))).findAny();
if (remotePortByDesc.isPresent()) {
return remotePortByDesc.get();
} else {
int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
return new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber), true, annotations.build());
}
}
}
use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class PortCodec method decode.
/**
* {@inheritDoc}
*
* Note: Result of {@link Port#element()} returned Port object,
* is not a full Device object.
* Only it's DeviceId can be used.
*/
@Override
public Port decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText());
Device device = new DummyDevice(did);
PortNumber number = portNumber(json.get(PORT_NAME).asText());
boolean isEnabled = json.get(IS_ENABLED).asBoolean();
Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase());
long portSpeed = json.get(PORT_SPEED).asLong();
Annotations annotations = extractAnnotations(json, context);
return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations);
}
use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForMigration.
/**
* Tests the process port added method for migration case.
*/
@Test
public void testProcessPortAddedForMigration() {
org.onosproject.net.Port port = new DefaultPort(DEV1, P2, true, ANNOTATIONS);
target.processPortAdded(port);
HostId hostId = HostId.hostId(HOST_MAC);
verifyHostLocationResult(hostId, HOST_LOC12);
}
use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForNewAddition.
/**
* Tests the process port added method for new addition case.
*/
@Test
public void testProcessPortAddedForNewAddition() {
org.onosproject.net.Port port = new DefaultPort(DEV2, P1, true, ANNOTATIONS);
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV2, port);
target.portAddedHelper(event);
HostId hostId = HostId.hostId(HOST_MAC2);
HostDescription hostDesc = new DefaultHostDescription(HOST_MAC2, VlanId.NONE, new HostLocation(CP21, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS);
verifyHostResult(hostId, hostDesc);
}
use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class SimpleDeviceStore method composePort.
/**
* Returns a Port, merging description given from multiple Providers.
*
* @param device device the port is on
* @param number port number
* @param descsMap Collection of Descriptions from multiple providers
* @return Port instance
*/
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
ProviderId primary = pickPrimaryPid(descsMap);
DeviceDescriptions primDescs = descsMap.get(primary);
// if no primary, assume not enabled
// TODO: revisit this default port enabled/disabled behavior
boolean isEnabled = false;
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
final PortDescription portDesc = primDescs.getPortDesc(number);
if (portDesc != null) {
isEnabled = portDesc.isEnabled();
annotations = merge(annotations, portDesc.annotations());
}
for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
if (e.getKey().equals(primary)) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
if (otherPortDesc != null) {
annotations = merge(annotations, otherPortDesc.annotations());
}
}
return portDesc == null ? new DefaultPort(device, number, false, annotations) : new DefaultPort(device, number, isEnabled, portDesc.type(), portDesc.portSpeed(), annotations);
}
Aggregations