use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class OpenFlowDeviceProviderTest method switchChanged.
// test receiving features reply
@Test
public void switchChanged() {
controller.listener.switchChanged(DPID1);
Collection<PortDescription> updatedDescr = registry.ports.values();
for (PortDescription pd : updatedDescr) {
assertNotNull("Switch change not handled by the provider service", pd);
}
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class PolatisDeviceDescription method discoverPortDetails.
/**
* Discovers port details, for Polatis Snmp device.
*
* @return port list
*/
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = Lists.newArrayList();
List<TableEvent> events;
DeviceId deviceId = handler().data().deviceId();
try {
OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
events = getTable(handler(), columnOIDs);
} catch (IOException e) {
log.error("Error reading ports table for device {} exception {}", deviceId, e);
return ports;
}
if (events == null) {
log.error("Error reading ports table for device {}", deviceId);
return ports;
}
for (TableEvent event : events) {
if (event == null) {
log.error("Error reading event for device {}", deviceId);
continue;
}
VariableBinding[] columns = event.getColumns();
if (columns == null) {
log.error("Error reading columns for device {} event {}", deviceId, event);
continue;
}
VariableBinding portColumn = columns[0];
if (portColumn == null) {
continue;
}
int port = event.getIndex().last();
boolean enabled = (portColumn.getVariable().toInt() == 1);
PortNumber portNumber = PortNumber.portNumber(port);
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
ports.add(p);
}
return ports;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class PolatisDeviceDescription method discoverPortDetails.
/**
* Discovers port details, for polatis device.
*
* @return port list
*/
@Override
public List<PortDescription> discoverPortDetails() {
log.debug("Discovering ports on Polatis switch...");
DeviceService deviceService = handler().get(DeviceService.class);
DeviceId deviceID = handler().data().deviceId();
Device device = deviceService.getDevice(deviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
String reply = netconfGet(handler(), getPortsFilter());
List<PortDescription> descriptions = parsePorts(reply, numInputPorts, numOutputPorts);
return ImmutableList.copyOf(descriptions);
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class GossipDeviceStoreTest 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);
Capture<InternalPortStatusEvent> message = Capture.newInstance();
Capture<MessageSubject> subject = Capture.newInstance();
Capture<Function<InternalPortStatusEvent, byte[]>> encoder = Capture.newInstance();
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
final DefaultPortDescription desc = DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build();
DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, desc);
assertEquals(PORT_UPDATED, event.type());
assertDevice(DID1, SW1, event.subject());
assertEquals(P1, event.port().number());
assertFalse("Port is disabled", event.port().isEnabled());
verify(clusterCommunicator);
assertInternalPortStatusEvent(NID1, DID1, PID, desc, NO_ANNOTATION, message, subject, encoder);
assertTrue(message.hasCaptured());
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class GossipDeviceStoreTest 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);
Capture<InternalDeviceEvent> message = Capture.newInstance();
Capture<MessageSubject> subject = Capture.newInstance();
Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
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());
verify(clusterCommunicator);
// TODO: verify broadcast message
assertTrue(message.hasCaptured());
// 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());
}
Aggregations