Search in sources :

Example 1 with DeviceInterfaceDescription

use of org.onosproject.net.device.DeviceInterfaceDescription in project onos by opennetworkinglab.

the class XmlParserCisco method getInterfacesFromConfig.

/**
 * Parses device configuration and returns the descriptions of the device
 * interfaces.
 *
 * @param cfg an hierarchical configuration
 * @return list of interface descriptions for the device
 */
public static List<DeviceInterfaceDescription> getInterfacesFromConfig(HierarchicalConfiguration cfg) {
    List<DeviceInterfaceDescription> intfs = Lists.newArrayList();
    List<HierarchicalConfiguration> subtrees = cfg.configurationsAt("data.xml-config-data.Device-Configuration.interface");
    for (HierarchicalConfiguration intfConfig : subtrees) {
        String intfName = getInterfaceName(intfConfig);
        DeviceInterfaceDescription.Mode intfMode = getInterfaceMode(intfConfig);
        List<VlanId> intfVlans = getInterfaceVlans(intfConfig, intfMode);
        short intfLimit = getInterfaceLimit(intfConfig);
        boolean intfLimited = (intfLimit == NO_LIMIT ? false : true);
        DeviceInterfaceDescription intf = new DefaultDeviceInterfaceDescription(intfName, intfMode, intfVlans, intfLimited, intfLimit);
        intfs.add(intf);
    }
    return intfs;
}
Also used : DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) VlanId(org.onlab.packet.VlanId)

Example 2 with DeviceInterfaceDescription

use of org.onosproject.net.device.DeviceInterfaceDescription in project onos by opennetworkinglab.

the class ServerInterfaceConfig method getInterfaces.

@Override
public List<DeviceInterfaceDescription> getInterfaces() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to get interfaces for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for interface discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No interfaces available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
        Mode devMode = getDeviceMode(devVlanIds);
        // Create an interface description and add it to the list
        intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
    }
    return ImmutableList.copyOf(intfDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) Mode(org.onosproject.net.device.DeviceInterfaceDescription.Mode) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) VlanId(org.onlab.packet.VlanId)

Example 3 with DeviceInterfaceDescription

use of org.onosproject.net.device.DeviceInterfaceDescription in project onos by opennetworkinglab.

the class DeviceInterfacesListCommand method printDevice.

private void printDevice(DeviceService deviceService, DriverService driverService, Device device) {
    super.printDevice(deviceService, device);
    if (!device.is(InterfaceConfig.class)) {
        // The relevant behavior is not supported by the device.
        print(ERROR_RESULT);
        return;
    }
    DriverHandler h = driverService.createHandler(device.id());
    InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
    List<DeviceInterfaceDescription> interfaces = interfaceConfig.getInterfaces();
    if (interfaces == null) {
        print(ERROR_RESULT);
    } else if (interfaces.isEmpty()) {
        print(NO_INTERFACES);
    } else {
        interfaces.forEach(this::printInterface);
    }
}
Also used : InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 4 with DeviceInterfaceDescription

use of org.onosproject.net.device.DeviceInterfaceDescription in project onos by opennetworkinglab.

the class XmlParserCiscoTest method getExpectedIntfs.

private List<DeviceInterfaceDescription> getExpectedIntfs() {
    List<DeviceInterfaceDescription> intfs = new ArrayList<>();
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_1, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), NO_LIMIT, NO_RATE_LIMIT));
    List<VlanId> accessList = new ArrayList<>();
    accessList.add(ACCESS_VLAN);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_2, DeviceInterfaceDescription.Mode.ACCESS, accessList, NO_LIMIT, NO_RATE_LIMIT));
    List<VlanId> trunkList1 = new ArrayList<>();
    trunkList1.add(TRUNK_VLAN_1);
    trunkList1.add(TRUNK_VLAN_2);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_3, DeviceInterfaceDescription.Mode.TRUNK, trunkList1, NO_LIMIT, NO_RATE_LIMIT));
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_4, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), WITH_LIMIT, RATE_LIMIT_1));
    List<VlanId> trunkList2 = new ArrayList<>();
    trunkList2.add(TRUNK_VLAN_3);
    trunkList2.add(TRUNK_VLAN_4);
    trunkList2.add(TRUNK_VLAN_5);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_5, DeviceInterfaceDescription.Mode.TRUNK, trunkList2, WITH_LIMIT, RATE_LIMIT_2));
    return intfs;
}
Also used : DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) ArrayList(java.util.ArrayList) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) VlanId(org.onlab.packet.VlanId)

Example 5 with DeviceInterfaceDescription

use of org.onosproject.net.device.DeviceInterfaceDescription in project onos by opennetworkinglab.

the class XmlParserCiscoTest method controllersConfig.

@Test
public void controllersConfig() {
    InputStream streamOrig = getClass().getResourceAsStream(CONFIG_XML_FILE);
    HierarchicalConfiguration cfgOrig = XmlConfigParser.loadXml(streamOrig);
    List<DeviceInterfaceDescription> actualIntfs = XmlParserCisco.getInterfacesFromConfig(cfgOrig);
    assertEquals("Interfaces were not retrieved from configuration", getExpectedIntfs(), actualIntfs);
}
Also used : InputStream(java.io.InputStream) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Test(org.junit.Test)

Aggregations

DeviceInterfaceDescription (org.onosproject.net.device.DeviceInterfaceDescription)5 DefaultDeviceInterfaceDescription (org.onosproject.net.device.DefaultDeviceInterfaceDescription)4 VlanId (org.onlab.packet.VlanId)3 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)1 NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)1 DeviceId (org.onosproject.net.DeviceId)1 InterfaceConfig (org.onosproject.net.behaviour.InterfaceConfig)1 Mode (org.onosproject.net.device.DeviceInterfaceDescription.Mode)1 DriverHandler (org.onosproject.net.driver.DriverHandler)1