use of org.onosproject.net.Port 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.Port in project onos by opennetworkinglab.
the class PortStatsDriver method updatePorts.
public void updatePorts(Device device) {
Set<PortStatistics> portStats = new HashSet<>();
for (Port port : deviceService.getPorts(device.id())) {
portStats.add(DefaultPortStatistics.builder().setBytesReceived(Math.abs(random.nextInt())).setBytesSent(Math.abs(random.nextInt())).setPacketsReceived(Math.abs(random.nextInt())).setPacketsSent(Math.abs(random.nextInt())).setDurationSec(2).setDeviceId(device.id()).setPort(port.number()).build());
}
deviceProviderService.updatePortStatistics(device.id(), portStats);
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class ZtePortStatisticsDiscovery method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
DeviceId deviceId = handler().data().deviceId();
LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
NetconfController controller = handler().get(NetconfController.class);
if (null == controller) {
LOG.error("Cannot find NetconfController");
return null;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
if (null == session) {
LOG.error("No session available for device {}", deviceId);
return null;
}
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Collection<PortStatistics> portStatistics = Lists.newArrayList();
ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
return portStatistics;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class ZteTransceiver method enable.
@Override
public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
DeviceId deviceId = handler().data().deviceId();
log.info("Discovering ZTE device {}", deviceId);
Port clientPort = handler().get(DeviceService.class).getPort(deviceId, client);
if (clientPort == null) {
log.warn("{} does not exist on {}", client, deviceId);
return Collections.emptyList();
}
String clientName = clientPort.annotations().value(OC_NAME);
if (Strings.isNullOrEmpty(clientName)) {
log.warn("{} annotations not exist on {}@{}", OC_NAME, client, deviceId);
return Collections.emptyList();
}
Port linePort = handler().get(DeviceService.class).getPort(deviceId, line);
if (linePort == null) {
log.warn("{} does not exist on {}", line, deviceId);
return Collections.emptyList();
}
String lineName = linePort.annotations().value(OC_NAME);
if (Strings.isNullOrEmpty(lineName)) {
log.warn("{} annotations not exist on {}@{}", OC_NAME, line, deviceId);
return Collections.emptyList();
}
int clientIndex, lineIndex;
try {
clientIndex = getPortIndex(clientName);
lineIndex = getPortIndex(lineName);
} catch (IllegalArgumentException e) {
return Collections.emptyList();
}
// create <terminal-device xmlns="http://openconfig.net/yang/terminal-device">
// </terminal-device>
OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
// add <logical-channels></logical-channels>
OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(terminalDevice);
// add <channel><index>"clientIndex"</index></channel>
OpenConfigChannelHandler channel = new OpenConfigChannelHandler(clientIndex, logicalChannels);
// add <channel xc:operation="merge/delete">
if (enable) {
channel.addAnnotation(ANOTATION_NAME, Operation.MERGE.value());
} else {
channel.addAnnotation(ANOTATION_NAME, Operation.DELETE.value());
}
// add <config><index>"clientIndex"</index></config>
OpenConfigConfigOfChannelHandler configOfChannel = new OpenConfigConfigOfChannelHandler(channel);
configOfChannel.addIndex(clientIndex);
// add <logical-channel-assignments></logical-channel-assignments>
OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = new OpenConfigLogicalChannelAssignmentsHandler(channel);
// add <assignment><index>1</index></assignment>
OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(1, logicalChannelAssignments);
// add <config><assignment-type>LOGICAL_CHANNEL</assignment-type>
// <logical-channel>"lineIndex"</logical-channel>
// </config>
OpenConfigConfigOfAssignmentHandler configOfAssignment = new OpenConfigConfigOfAssignmentHandler(assignment);
configOfAssignment.addAssignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL);
configOfAssignment.addLogicalChannel("" + lineIndex);
return terminalDevice.getListCharSequence();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class LldpLinkProviderTest method portSuppressedByPortBlacklist.
@Test
public void portSuppressedByPortBlacklist() {
// add device in stub DeviceService without suppression configured
deviceService.putDevice(device(DID3));
deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
final long portno3 = 3L;
final Port port3 = port(DID3, portno3, true);
final ConnectPoint cpDid3no3 = new ConnectPoint(DID3, PortNumber.portNumber(portno3));
portBlacklist.add(cpDid3no3);
// suppressed port added to non-suppressed device
deviceService.putPorts(DID3, port3);
deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3));
configListener.event(new NetworkConfigEvent(Type.CONFIG_ADDED, cpDid3no3, LinkDiscoveryFromPort.class));
// discovery helper should be there turned on
assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
// but port is not a discovery target
assertFalse("Discoverer should not contain the port there", provider.discoverers.get(DID3).containsPort(portno3));
}
Aggregations