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 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 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;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class DeviceInjectionConfigMonitor method injectDevice.
private void injectDevice(DeviceId did) {
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
if (discovery.isPresent()) {
providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
providerService.updatePorts(did, discovery.get().discoverPortDetails());
} else {
String unk = "UNKNOWN";
DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
providerService.deviceConnected(did, desc);
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
int numPorts = Integer.parseInt(ports);
List<PortDescription> portDescs = new ArrayList<>(numPorts);
for (int i = 1; i <= numPorts; ++i) {
// TODO inject port details if something like BasicPortConfig was created
PortNumber number = portNumber(i);
boolean isEnabled = true;
portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
}
providerService.updatePorts(did, portDescs);
}
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class FujitsuT100DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.get(requestBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
return ImmutableList.of();
}
List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
return ImmutableList.copyOf(descriptions);
}
Aggregations