use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = new ArrayList<PortDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, will be retried", deviceId);
return ports;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "logicalPorts");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList) xp.evaluate("interfaces/interface/config", logicalPorts, XPathConstants.NODESET);
int count = nl.getLength();
Node node;
for (int i = 0; i < count; i += 1) {
node = nl.item(i);
if (xp.evaluate("type/text()", node).equals("ettp")) {
ports.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(xp.evaluate("name/text()", node))).isEnabled(Boolean.valueOf(xp.evaluate("admin-status/text()", node))).portSpeed(portSpeedToLong(xp.evaluate("port-speed/text()", node))).type(Port.Type.PACKET).build());
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port information for device {}, {}", deviceId, e);
}
return ports;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<LinkDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
return links;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
DeviceService deviceService = this.handler().get(DeviceService.class);
Iterable<Device> devices = deviceService.getAvailableDevices();
Map<String, Device> lookup = new HashMap<String, Device>();
for (Device d : devices) {
lookup.put(d.chassisId().toString().toUpperCase(), d);
}
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
int count = ifaces.getLength();
Node iface;
Node destChassis;
for (int i = 0; i < count; i += 1) {
iface = ifaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
if (destChassis != null) {
Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
} else {
log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
}
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve links for device {}, {}", deviceId, e);
}
return links;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo");
Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion");
XPath xp = XPathFactory.newInstance().newXPath();
String mac = xp.evaluate("components/component/properties/property/state/value/text()", systemInfo).toUpperCase();
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, xp.evaluate("components/component/state/mfg-name/text()", systemInfo), xp.evaluate("components/component/state/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), xp.evaluate("components/component/state/serial-no/text()", systemInfo), new ChassisId(Long.valueOf(mac, 16)));
} catch (XPathExpressionException | NetconfException ne) {
log.error("failed to query system info from device {}", handler().data().deviceId(), ne);
}
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5162", "Unknown", "Unknown", new ChassisId());
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method addTrunkMode.
/**
* Adds a trunk interface for VLANs.
*
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
*/
@Override
public boolean addTrunkMode(String intf, List<VlanId> vlanIds) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addTrunkModeBuilder(intf, vlanIds));
} catch (NetconfException e) {
log.error("Failed to configure trunk mode for VLAN ID {} on device {} interface {}.", vlanIds, handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method addAccessMode.
/**
* Adds an access interface to a VLAN.
*
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
@Override
public boolean addAccessMode(String intf, VlanId vlanId) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addAccessModeBuilder(intf, vlanId));
} catch (NetconfException e) {
log.error("Failed to configure VLAN ID {} on device {} interface {}.", vlanId, handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
Aggregations