use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method getCircuitPackByName.
/**
* Get config and status info for a specific circuit pack as a
* list of XML hierarchical configs.
* @param session the NETConf session to the OpenROADM device.
* @param cpName the name of the requested circuit-pack
* @return the hierarchical conf. for the circuit pack.
*/
HierarchicalConfiguration getCircuitPackByName(NetconfSession session, String cpName) {
try {
String reply = session.rpc(getDeviceCircuitPackByNameBuilder(cpName)).get();
XMLConfiguration cpConf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
cpConf.setExpressionEngine(new XPathExpressionEngine());
List<HierarchicalConfiguration> cPacks = cpConf.configurationsAt("/data/org-openroadm-device/circuit-packs");
// It shouldn't happen they are > 1
if (cPacks.size() > 1) {
log.warn("[OPENROADM] More than one circuit pack with the same name. Using first one");
}
return cPacks.get(0);
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception getting circuit pack {}: {}", did(), cpName, e);
return null;
}
}
use of org.onosproject.netconf.NetconfException 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;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method removeFlowRule.
protected boolean removeFlowRule(NetconfSession session, TerminalDeviceFlowRule rule) throws NetconfException {
// --- disable the line port
if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS || rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
FlowRuleParser frp = new FlowRuleParser(rule);
String componentName = frp.getPortNumber().toString();
log.info("Removing LINE FlowRule device {} line port {}", did(), componentName);
try {
setLogicalChannel(session, OPERATION_DISABLE, componentName);
} catch (NetconfException e) {
log.error("Error disabling the logical channel line side");
return false;
}
}
// --- disable the line port
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS || rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
String clientPortName;
String linePortName;
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
clientPortName = rule.inPort().toString();
linePortName = rule.outPort().toString();
} else {
clientPortName = rule.outPort().toString();
linePortName = rule.inPort().toString();
}
log.debug("Removing CLIENT FlowRule device {} client port: {}, line port {}", did(), clientPortName, linePortName);
try {
setLogicalChannelAssignment(session, OPERATION_DISABLE, clientPortName, linePortName, DEFAULT_ASSIGNMENT_INDEX, DEFAULT_ALLOCATION_INDEX);
} catch (NetconfException e) {
log.error("Error disabling the logical channel assignment");
return false;
}
}
return true;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchLineConnectionFromDevice.
private List<FlowRule> fetchLineConnectionFromDevice(String channel, Frequency centralFreq) {
List<FlowRule> confirmedRules = new ArrayList<>();
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
log.debug("fetchOpticalConnectionsFromDevice {} frequency {}", did(), centralFreq);
// Build the corresponding flow rule as expected
// Selector including port and ochSignal
// Treatment including port
PortNumber inputPortNumber = PortNumber.portNumber(channel);
PortNumber outputPortNumber = PortNumber.portNumber(channel);
log.debug("fetchOpticalConnectionsFromDevice {} port {}-{}", did(), inputPortNumber, outputPortNumber);
TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).add(Criteria.matchLambda(toOchSignal(centralFreq, 50.0))).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).build();
TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(outputPortNumber).build();
TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).build();
TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(toOchSignal(centralFreq, 50.0))).setOutput(outputPortNumber).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("fetchOpticalConnectionsFromDevice {} DROP LINE rule included in the cache {}", did(), cacheDropRule);
} else {
log.warn("fetchOpticalConnectionsFromDevice {} DROP LINE rule not included in cache", did());
}
// Include the ADD rule to the retrieved rules if found in cache
if ((cacheAddRule != null)) {
confirmedRules.add(cacheAddRule);
log.debug("fetchOpticalConnectionsFromDevice {} ADD LINE rule included in the cache {}", did(), cacheAddRule.selector());
} else {
log.warn("fetchOpticalConnectionsFromDevice {} ADD LINE rule not included in cache", did());
}
// If neither Add or Drop rules are present in the cache, remove configuration from the device
if ((cacheDropRule == null) && (cacheAddRule == null)) {
log.warn("fetchOpticalConnectionsFromDevice {} 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 LINE rule from device", e);
}
}
return confirmedRules;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NetconfGetConfigCommand method doExecute.
@Override
protected void doExecute() {
deviceId = DeviceId.deviceId(uri);
NetconfController controller = get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
NetconfDevice device = controller.getDevicesMap().get(deviceId);
if (device == null) {
print("Netconf device object not found for %s", deviceId);
return;
}
NetconfSession session = device.getSession();
if (session == null) {
print("Netconf session not found for %s", deviceId);
return;
}
try {
CharSequence res = session.asyncGetConfig(datastore(datastore.toLowerCase())).get(timeoutSec, TimeUnit.SECONDS);
print("%s", res);
} catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}
}
Aggregations