Andreas Papazois | 1ed54cf | 2016-05-04 16:22:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.cisco; |
| 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | import org.apache.commons.configuration.HierarchicalConfiguration; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | import org.onosproject.drivers.utilities.XmlConfigParser; |
| 24 | import org.onosproject.net.device.DefaultDeviceInterfaceDescription; |
| 25 | import org.onosproject.net.device.DeviceInterfaceDescription; |
| 26 | |
| 27 | import java.io.InputStream; |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.List; |
| 30 | |
| 31 | import static org.junit.Assert.assertEquals; |
| 32 | |
| 33 | /** |
| 34 | * Tests the parser for Netconf XML configurations and replies from Cisco devices. |
| 35 | */ |
| 36 | public class XmlParserCiscoTest { |
| 37 | |
| 38 | private static final String INTF_NAME_1 = "GigabitEthernet0/1"; |
| 39 | private static final String INTF_NAME_2 = "GigabitEthernet0/2"; |
| 40 | private static final String INTF_NAME_3 = "GigabitEthernet0/3"; |
| 41 | private static final String INTF_NAME_4 = "GigabitEthernet0/4"; |
| 42 | private static final String INTF_NAME_5 = "GigabitEthernet0/5"; |
| 43 | private static final VlanId ACCESS_VLAN = VlanId.vlanId((short) 100); |
| 44 | private static final VlanId TRUNK_VLAN_1 = VlanId.vlanId((short) 200); |
| 45 | private static final VlanId TRUNK_VLAN_2 = VlanId.vlanId((short) 201); |
| 46 | private static final VlanId TRUNK_VLAN_3 = VlanId.vlanId((short) 300); |
| 47 | private static final VlanId TRUNK_VLAN_4 = VlanId.vlanId((short) 301); |
| 48 | private static final VlanId TRUNK_VLAN_5 = VlanId.vlanId((short) 302); |
| 49 | private static final short NO_RATE_LIMIT = -1; |
| 50 | private static final short RATE_LIMIT_1 = 75; |
| 51 | private static final short RATE_LIMIT_2 = 50; |
| 52 | private static final boolean NO_LIMIT = false; |
| 53 | private static final boolean WITH_LIMIT = true; |
| 54 | private static final String CONFIG_XML_FILE = "/testGetConfig.xml"; |
| 55 | |
| 56 | @Test |
| 57 | public void controllersConfig() { |
| 58 | InputStream streamOrig = getClass().getResourceAsStream(CONFIG_XML_FILE); |
| 59 | HierarchicalConfiguration cfgOrig = XmlConfigParser.loadXml(streamOrig); |
| 60 | List<DeviceInterfaceDescription> actualIntfs = |
| 61 | XmlParserCisco.getInterfacesFromConfig(cfgOrig); |
| 62 | assertEquals("Interfaces were not retrieved from configuration", |
| 63 | getExpectedIntfs(), actualIntfs); |
| 64 | } |
| 65 | |
| 66 | private List<DeviceInterfaceDescription> getExpectedIntfs() { |
| 67 | List<DeviceInterfaceDescription> intfs = new ArrayList<>(); |
| 68 | intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_1, |
| 69 | DeviceInterfaceDescription.Mode.NORMAL, |
| 70 | Lists.newArrayList(), |
| 71 | NO_LIMIT, |
| 72 | NO_RATE_LIMIT)); |
| 73 | |
| 74 | List<VlanId> accessList = new ArrayList<>(); |
| 75 | accessList.add(ACCESS_VLAN); |
| 76 | intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_2, |
| 77 | DeviceInterfaceDescription.Mode.ACCESS, |
| 78 | accessList, |
| 79 | NO_LIMIT, |
| 80 | NO_RATE_LIMIT)); |
| 81 | |
| 82 | List<VlanId> trunkList1 = new ArrayList<>(); |
| 83 | trunkList1.add(TRUNK_VLAN_1); |
| 84 | trunkList1.add(TRUNK_VLAN_2); |
| 85 | intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_3, |
| 86 | DeviceInterfaceDescription.Mode.TRUNK, |
| 87 | trunkList1, |
| 88 | NO_LIMIT, |
| 89 | NO_RATE_LIMIT)); |
| 90 | |
| 91 | intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_4, |
| 92 | DeviceInterfaceDescription.Mode.NORMAL, |
| 93 | Lists.newArrayList(), |
| 94 | WITH_LIMIT, |
| 95 | RATE_LIMIT_1)); |
| 96 | |
| 97 | List<VlanId> trunkList2 = new ArrayList<>(); |
| 98 | trunkList2.add(TRUNK_VLAN_3); |
| 99 | trunkList2.add(TRUNK_VLAN_4); |
| 100 | trunkList2.add(TRUNK_VLAN_5); |
| 101 | intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_5, |
| 102 | DeviceInterfaceDescription.Mode.TRUNK, |
| 103 | trunkList2, |
| 104 | WITH_LIMIT, |
| 105 | RATE_LIMIT_2)); |
| 106 | return intfs; |
| 107 | } |
| 108 | } |