use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class SimpleDeviceStoreTest method testRemoveDevice.
@Test
public final void testRemoveDevice() {
putDevice(DID1, SW1, A1);
List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).annotations(A2).build());
deviceStore.updatePorts(PID, DID1, pds);
putDevice(DID2, SW1);
assertEquals(2, deviceStore.getDeviceCount());
assertEquals(1, deviceStore.getPorts(DID1).size());
assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations(), A1);
assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations(), A2);
DeviceEvent event = deviceStore.removeDevice(DID1);
assertEquals(DEVICE_REMOVED, event.type());
assertDevice(DID1, SW1, event.subject());
assertEquals(1, deviceStore.getDeviceCount());
assertEquals(0, deviceStore.getPorts(DID1).size());
// putBack Device, Port w/o annotation
putDevice(DID1, SW1);
List<PortDescription> pds2 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
deviceStore.updatePorts(PID, DID1, pds2);
// annotations should not survive
assertEquals(2, deviceStore.getDeviceCount());
assertEquals(1, deviceStore.getPorts(DID1).size());
assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations());
assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations());
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class SimpleDeviceStoreTest method testUpdatePortStatus.
@Test
public final void testUpdatePortStatus() {
putDevice(DID1, SW1);
List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
deviceStore.updatePorts(PID, DID1, pds);
DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build());
assertEquals(PORT_UPDATED, event.type());
assertDevice(DID1, SW1, event.subject());
assertEquals(P1, event.port().number());
assertFalse("Port is disabled", event.port().isEnabled());
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
// Retrieve the device ID
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// .. and object
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to discover ports for device {}", deviceId);
return Collections.EMPTY_LIST;
}
if (device == null) {
log.error("No device with ID {} is available for port discovery", deviceId);
return Collections.EMPTY_LIST;
}
if ((device.nics() == null) || (device.nics().size() == 0)) {
log.error("No ports available on {}", deviceId);
return Collections.EMPTY_LIST;
}
// List of port descriptions to return
List<PortDescription> portDescriptions = Lists.newArrayList();
// Sorted list of NIC ports
Set<NicDevice> nics = new TreeSet(device.nics());
// Iterate through the NICs of this device to populate the list
for (NicDevice nic : nics) {
// Include the name of this device as an annotation
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, nic.name());
// Create a port description and add it to the list
portDescriptions.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(nic.portNumber())).isEnabled(nic.status()).type(nic.portType()).portSpeed(nic.speed()).annotations(annotations.build()).build());
log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", deviceId, nic.portNumber(), nic.status() ? "up" : "down", nic.speed());
}
return ImmutableList.copyOf(portDescriptions);
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class PolatisLinkDiscovery method checkPeer.
private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
// check peerCP exists and is available (either via device service or direct from device)
DeviceId peerDeviceID = peerCP.deviceId();
boolean result = false;
DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
if (deviceService.isAvailable(peerDeviceID)) {
log.trace("Peer device {} exists", peerDeviceID.toString());
Device device = deviceService.getDevice(peerDeviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
List<Port> ports = deviceService.getPorts(peerDeviceID);
PortNumber farEndPortNum = peerCP.port();
Port port = deviceService.getPort(peerCP);
if (port != null) {
if (port.isEnabled()) {
log.trace("Peer port {} exists", port.number().toLong());
// check far end peer-port entry (use device service or retrieve direct from switch)
Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
if (direct) {
log.trace("Checking device {} DIRECT", handler.data().deviceId());
// A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
NetconfController controller = checkNotNull(handler.get(NetconfController.class));
NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
farEndPortPeerportData = farEndPortPeerportDataDirect;
}
if (!farEndPortPeerportData.equals("")) {
if (farEndPortPeerportData.charAt(0) == '{') {
log.trace("Far-end peer-port value:" + farEndPortPeerportData);
ObjectMapper mapper = new ObjectMapper();
ConnectPoint checkNearEndCP = null;
try {
checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
} catch (JsonProcessingException jpe) {
log.trace("Error processing peer-port JSON: {}", jpe.toString());
}
if (nearEndCP.equals(checkNearEndCP)) {
log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
result = true;
} else {
log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
}
}
} else {
log.trace("Null peer-port entry for far-end port ({})", peerCP);
}
} else {
log.trace("Peer port {} is DISABLED", port);
}
} else {
log.trace("Peer port {} does not exist", port);
}
} else {
log.trace("Far end device does not exist or is not available");
}
return result;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class PolatisUtility method parsePorts.
/**
* Returns a list of PortDescriptions from parsing the content of the reply to a get[-config] call to a
* Polatis switch.
*
* @param content XML to be parsed as string
* @param numInputPorts Number of input ports
* @param numOutputPorts Number of output ports
* @return List of ports as PortDescription objects
*/
public static List<PortDescription> parsePorts(String content, int numInputPorts, int numOutputPorts) {
List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTCONFIG);
List<PortDescription> portDescriptions = new ArrayList<PortDescription>();
for (HierarchicalConfiguration portConfig : subtrees) {
PortDescription parsedPort = parsePort(portConfig, numInputPorts, numOutputPorts == 0 ? true : false);
portDescriptions.add(parsedPort);
}
return portDescriptions;
}
Aggregations