use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class GossipDeviceStoreTest method testGetPorts.
@Test
public final void testGetPorts() {
putDevice(DID1, SW1);
putDevice(DID2, SW1);
List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
deviceStore.updatePorts(PID, DID1, pds);
Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
List<Port> ports = deviceStore.getPorts(DID1);
for (Port port : ports) {
assertTrue("Port is enabled", port.isEnabled());
assertTrue("PortNumber is one of expected", expectedPorts.remove(port.number()));
}
assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());
assertTrue("DID2 has no ports", deviceStore.getPorts(DID2).isEmpty());
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class GossipDeviceStoreTest method testUpdatePorts.
@Test
public final void testUpdatePorts() {
putDevice(DID1, SW1);
List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
Capture<InternalDeviceEvent> message = Capture.newInstance();
Capture<MessageSubject> subject = Capture.newInstance();
Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
List<DeviceEvent> events = deviceStore.updatePorts(PID, DID1, pds);
verify(clusterCommunicator);
// TODO: verify broadcast message
assertTrue(message.hasCaptured());
Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
for (DeviceEvent event : events) {
assertEquals(PORT_ADDED, event.type());
assertDevice(DID1, SW1, event.subject());
assertTrue("PortNumber is one of expected", expectedPorts.remove(event.port().number()));
assertTrue("Port is enabled", event.port().isEnabled());
}
assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());
List<PortDescription> pds2 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P3).isEnabled(true).build());
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
events = deviceStore.updatePorts(PID, DID1, pds2);
verify(clusterCommunicator);
// TODO: verify broadcast message
assertTrue(message.hasCaptured());
assertFalse("event should be triggered", events.isEmpty());
for (DeviceEvent event : events) {
PortNumber num = event.port().number();
if (P1.equals(num)) {
assertEquals(PORT_UPDATED, event.type());
assertDevice(DID1, SW1, event.subject());
assertFalse("Port is disabled", event.port().isEnabled());
} else if (P2.equals(num)) {
fail("P2 event not expected.");
} else if (P3.equals(num)) {
assertEquals(PORT_ADDED, event.type());
assertDevice(DID1, SW1, event.subject());
assertTrue("Port is enabled", event.port().isEnabled());
} else {
fail("Unknown port number encountered: " + num);
}
}
List<PortDescription> pds3 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
events = deviceStore.updatePorts(PID, DID1, pds3);
verify(clusterCommunicator);
// TODO: verify broadcast message
assertTrue(message.hasCaptured());
assertFalse("event should be triggered", events.isEmpty());
for (DeviceEvent event : events) {
PortNumber num = event.port().number();
if (P1.equals(num)) {
fail("P1 event not expected.");
} else if (P2.equals(num)) {
fail("P2 event not expected.");
} else if (P3.equals(num)) {
assertEquals(PORT_REMOVED, event.type());
assertDevice(DID1, SW1, event.subject());
assertTrue("Port was enabled", event.port().isEnabled());
} else {
fail("Unknown port number encountered: " + num);
}
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class DistributedStatisticStore method buildConnectPoint.
private ConnectPoint buildConnectPoint(FlowRule rule) {
PortNumber port = getOutput(rule);
if (port == null) {
return null;
}
ConnectPoint cp = new ConnectPoint(rule.deviceId(), port);
return cp;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OpenConfigGnmiDeviceDescriptionDiscovery method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
if (!setupBehaviour("discoverPortDetails()")) {
return Collections.emptyList();
}
log.debug("Discovering port details on device {}", handler().data().deviceId());
final GetResponse response = Futures.getUnchecked(client.get(buildPortStateRequest()));
final Map<String, DefaultPortDescription.Builder> ports = Maps.newHashMap();
final Map<String, DefaultAnnotations.Builder> annotations = Maps.newHashMap();
final Map<String, PortNumber> portIds = Maps.newHashMap();
// Creates port descriptions with port name and port number
response.getNotificationList().forEach(notification -> {
notification.getUpdateList().forEach(update -> {
// /interfaces/interface[name=ifName]/state/...
final String ifName = update.getPath().getElem(1).getKeyMap().get("name");
if (!ports.containsKey(ifName)) {
ports.put(ifName, DefaultPortDescription.builder());
annotations.put(ifName, DefaultAnnotations.builder());
}
final DefaultPortDescription.Builder builder = ports.get(ifName);
final DefaultAnnotations.Builder annotationsBuilder = annotations.get(ifName);
parseInterfaceInfo(update, ifName, builder, annotationsBuilder, portIds);
});
});
final List<PortDescription> portDescriptionList = Lists.newArrayList();
ports.forEach((key, value) -> {
// For devices not providing last-change, we set it to 0
final DefaultAnnotations.Builder annotationsBuilder = annotations.get(key);
if (!annotationsBuilder.build().keys().contains(LAST_CHANGE)) {
annotationsBuilder.set(LAST_CHANGE, String.valueOf(0));
}
/* Override port number if read port-id is enabled
and /interfaces/interface/state/id is available */
if (readPortId() && portIds.containsKey(key)) {
value.withPortNumber(portIds.get(key));
}
DefaultAnnotations annotation = annotations.get(key).build();
portDescriptionList.add(value.annotations(annotation).build());
});
return portDescriptionList;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OpenstackVtapManager method setOutputTable.
private void setOutputTable(DeviceId deviceId, Mode mode, IpAddress serverIp, boolean install) {
log.debug("setOutputTable[{}]: deviceId={}, mode={}, serverIp={}", install ? "add" : "remove", deviceId, mode, serverIp);
if (deviceId == null) {
return;
}
switch(mode) {
case GRE:
case VXLAN:
String tunnelName = getTunnelName(mode);
PortNumber vtapPort = portNumber(deviceId, tunnelName);
if (vtapPort != null) {
for (int idx = 0; idx < VTAP_TABLES.length; idx++) {
setOutputTableForTunnel(deviceId, VTAP_TABLES[idx][VTAP_TABLE_OUTPUT_IDX], vtapPort, serverIp, install);
}
} else {
log.warn("Vtap tunnel port {} doesn't exist", tunnelName);
}
break;
default:
log.warn("Invalid vtap network mode {}", mode);
break;
}
}
Aggregations