use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenconfigBitErrorRateState method getPreFecBer.
/**
* Get the BER value pre FEC.
*
* @param deviceId the device identifier
* @param port the port identifier
* @return the decimal value of BER
*/
@Override
public Optional<Double> getPreFecBer(DeviceId deviceId, PortNumber port) {
NetconfSession session = NetconfSessionUtility.getNetconfSession(deviceId, getController());
checkNotNull(session);
String preFecBerFilter = generateBerFilter(deviceId, port, PRE_FEC_BER_TAG);
String rpcRequest = getConfigOperation(preFecBerFilter);
log.debug("RPC call for fetching Pre FEC BER : {}", rpcRequest);
XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);
if (xconf == null) {
log.error("Error in executing Pre FEC BER RPC");
return Optional.empty();
}
try {
HierarchicalConfiguration config = xconf.configurationAt("data/components/component/transceiver/state/" + PRE_FEC_BER_TAG);
if (config == null || config.getString("instant") == null) {
return Optional.empty();
}
double ber = Float.valueOf(config.getString("instant")).doubleValue();
return Optional.of(ber);
} catch (IllegalArgumentException e) {
log.error("Error in fetching configuration : {}", e.getMessage());
return Optional.empty();
}
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class AbstractTerminalDeviceFlowRuleProgrammable method removeFlowRules.
/**
* Remove the specified flow rules.
*
* @param rules A collection of Flow Rules to be removed
* @return The collection of removed Flow Entries
*/
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
NetconfSession session = getNetconfSession();
if (session == null) {
openConfigError("null session");
return ImmutableList.of();
}
List<FlowRule> removed = new ArrayList<>();
for (FlowRule r : rules) {
try {
String connectionId = removeFlowRule(session, r);
getConnectionCache().remove(did(), connectionId);
removed.add(r);
} catch (Exception e) {
openConfigError("Error {}", e);
continue;
}
}
openConfigLog("removedFlowRules removed {}", removed.size());
return removed;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchClientConnectionFromDevice.
private List<FlowRule> fetchClientConnectionFromDevice(PortNumber clientPortNumber, PortNumber linePortNumber) {
List<FlowRule> confirmedRules = new ArrayList<>();
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
// Build the corresponding flow rule as expected
// Selector including port
// Treatment including port
log.debug("fetchClientConnectionsFromDevice {} client {} line {}", did(), clientPortNumber, linePortNumber);
TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(linePortNumber).build();
TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(clientPortNumber).build();
TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(clientPortNumber).build();
TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().setOutput(linePortNumber).build();
// Retrieved rules and cached rules are considered equal if both selector and treatment are equal
cacheAddRule = null;
cacheDropRule = null;
if (getConnectionCache().size(did()) != 0) {
cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
}
// Include the DROP rule to the retrieved rules if found in cache
if ((cacheDropRule != null)) {
confirmedRules.add(cacheDropRule);
log.debug("fetchClientConnectionsFromDevice {} DROP CLIENT rule in the cache {}", did(), cacheDropRule);
} else {
log.warn("fetchClientConnectionsFromDevice {} DROP CLIENT rule not found in cache", did());
}
// Include the ADD rule to the retrieved rules if found in cache
if ((cacheAddRule != null)) {
confirmedRules.add(cacheAddRule);
log.debug("fetchClientConnectionsFromDevice {} ADD CLIENT rule in the cache {}", did(), cacheAddRule);
} else {
log.warn("fetchClientConnectionsFromDevice {} ADD CLIENT rule not found in cache", did());
}
if ((cacheDropRule == null) && (cacheAddRule == null)) {
log.warn("fetchClientConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
try {
// TODO this is not required if allowExternalFlowRules
TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
removeFlowRule(session, addRule);
TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
removeFlowRule(session, dropRule);
} catch (NetconfException e) {
openConfigError("Error removing CLIENT rule from device", e);
}
}
return confirmedRules;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method discoverPortDetails.
/**
* Returns a list of PortDescriptions for the device.
*
* @return a list of descriptions.
*/
/*
* Assumptions: ROADM degree ports are Oms carrying 80 lambdas (should be
* configurable)
* ROADM SRG (client) ports are OCh carrying ODU4 (should be
* configurable)
*/
@Override
public List<PortDescription> discoverPortDetails() {
NetconfSession session = getNetconfSession(did());
if (session == null) {
log.error("discoverPortDetails null session for {}", did());
return ImmutableList.of();
}
if (!getDevice().annotations().keys().contains("openroadm-node-id")) {
log.error("Unable to run PortDiscovery: missing openroadm-node-id annotation." + " Probable failure during DeviceDiscovery. Aborting!");
return ImmutableList.of();
}
List<HierarchicalConfiguration> externalLinks = getExternalLinks(session);
List<PortDescription> list = new ArrayList<PortDescription>();
discoverDegreePorts(session, list, externalLinks);
discoverSrgPorts(session, list, externalLinks);
return list;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method discoverDeviceDetails.
/**
* Returns a DeviceDescription with Device info.
*
* @return DeviceDescription or null
*/
@Override
public DeviceDescription discoverDeviceDetails() {
boolean defaultAvailable = true;
NetconfDevice ncDevice = getNetconfDevice();
if (ncDevice == null) {
log.error("ONOS Error: Device reachable, deviceID {} is not in Map", did());
return null;
}
DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
// Some defaults
String vendor = "UNKNOWN";
String hwVersion = "2.2.0";
String swVersion = "2.2.0";
String serialNumber = "0x0000";
String chassisId = "0";
String nodeType = "rdm";
// Get the session, if null, at least we can use the defaults.
NetconfSession session = getNetconfSession(did());
if (session != null) {
try {
String reply = session.rpc(getDeviceDetailsBuilder()).get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
String nodeId = xconf.getString("data.org-openroadm-device.info.node-id", "");
if (nodeId.equals("")) {
log.error("[OPENROADM] {} org-openroadm-device node-id undefined, returning", did());
return null;
}
annotationsBuilder.set(AnnotationKeys.OPENROADM_NODEID, nodeId);
nodeType = xconf.getString("data.org-openroadm-device.info.node-type", "");
if (nodeType.equals("")) {
log.error("[OPENROADM] {} empty node-type", did());
return null;
}
vendor = xconf.getString("data.org-openroadm-device.info.vendor", vendor);
hwVersion = xconf.getString("data.org-openroadm-device.info.model", hwVersion);
swVersion = xconf.getString("data.org-openroadm-device.info.softwareVersion", swVersion);
serialNumber = xconf.getString("data.org-openroadm-device.info.serial-id", serialNumber);
chassisId = xconf.getString("data.org-openroadm-device.info.node-number", chassisId);
// GEOLOCATION
String longitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.longitude");
String latitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.latitude");
if (longitudeStr != null && latitudeStr != null) {
annotationsBuilder.set(org.onosproject.net.AnnotationKeys.LONGITUDE, longitudeStr).set(org.onosproject.net.AnnotationKeys.LATITUDE, latitudeStr);
}
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception", did());
return null;
}
} else {
log.debug("[OPENROADM] - No session {}", did());
}
log.debug("[OPENROADM] {} - VENDOR {} HWVERSION {} SWVERSION {} SERIAL {} CHASSIS {}", did(), vendor, hwVersion, swVersion, serialNumber, chassisId);
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
/*
* OpenROADM defines multiple devices (node types). This driver has been tested with
* ROADMS, (node type, "rdm"). Other devices can also be discovered, and this code is here
* for future developments - untested - it is likely that the XML documents
* are model specific.
*/
org.onosproject.net.Device.Type type;
if (nodeType.equals("rdm")) {
type = org.onosproject.net.Device.Type.ROADM;
} else if (nodeType.equals("ila")) {
type = org.onosproject.net.Device.Type.OPTICAL_AMPLIFIER;
} else if (nodeType.equals("xpdr")) {
type = org.onosproject.net.Device.Type.TERMINAL_DEVICE;
} else if (nodeType.equals("extplug")) {
type = org.onosproject.net.Device.Type.OTHER;
} else {
log.error("[OPENROADM] {} unsupported node-type", did());
return null;
}
DeviceDescription desc = new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotationsBuilder.build());
return desc;
}
Aggregations