Search in sources :

Example 26 with NetconfController

use of org.onosproject.netconf.NetconfController 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());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) NetconfController(org.onosproject.netconf.NetconfController)

Example 27 with NetconfController

use of org.onosproject.netconf.NetconfController 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))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Example 28 with NetconfController

use of org.onosproject.netconf.NetconfController 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))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Example 29 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class InterfaceConfigCiscoIosImpl method addRateLimit.

/**
 * Adds a rate limit on an interface.
 *
 * @param intf the name of the interface
 * @param limit the limit as a percentage
 * @return the result of operation
 */
@Override
public boolean addRateLimit(String intf, short limit) {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    String reply;
    try {
        reply = session.requestSync(addRateLimitBuilder(intf, limit));
    } catch (NetconfException e) {
        log.error("Failed to configure rate limit {}%% on device {} interface {}.", limit, handler().data().deviceId(), intf, e);
        return false;
    }
    return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Example 30 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class InterfaceConfigCiscoIosImpl method removeTrunkMode.

/**
 * Removes trunk mode configuration from an interface.
 *
 * @param intf the name of the interface
 * @return the result of operation
 */
@Override
public boolean removeTrunkMode(String intf) {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    String reply;
    try {
        reply = session.requestSync(removeTrunkModeBuilder(intf));
    } catch (NetconfException e) {
        log.error("Failed to remove trunk mode from device {} interface {}.", handler().data().deviceId(), intf, e);
        return false;
    }
    return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

NetconfController (org.onosproject.netconf.NetconfController)80 NetconfException (org.onosproject.netconf.NetconfException)61 DeviceId (org.onosproject.net.DeviceId)42 NetconfSession (org.onosproject.netconf.NetconfSession)39 DriverHandler (org.onosproject.net.driver.DriverHandler)22 MastershipService (org.onosproject.mastership.MastershipService)20 NetconfDevice (org.onosproject.netconf.NetconfDevice)20 XPath (javax.xml.xpath.XPath)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)16 Node (org.w3c.dom.Node)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 NodeList (org.w3c.dom.NodeList)8 DeviceService (org.onosproject.net.device.DeviceService)7 Device (org.onosproject.net.Device)6 PortDescription (org.onosproject.net.device.PortDescription)5 HashSet (java.util.HashSet)4 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)4