ivoutsas | 69b9763 | 2016-05-25 13:36:44 +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 | |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.AnnotationKeys; |
| 22 | import org.onosproject.net.DefaultAnnotations; |
| 23 | import org.onosproject.net.Port; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.device.DefaultPortDescription; |
| 26 | import org.onosproject.net.device.PortDescription; |
| 27 | |
| 28 | import java.io.InputStream; |
| 29 | import java.util.Scanner; |
| 30 | import java.util.ArrayList; |
| 31 | import java.util.List; |
| 32 | |
| 33 | |
| 34 | |
| 35 | import static org.junit.Assert.assertEquals; |
| 36 | |
| 37 | /** |
| 38 | * Tests the parser for Netconf TextBlock configurations and replies from Cisco devices. |
| 39 | */ |
| 40 | public class TextBlockParserCiscoTest { |
| 41 | |
| 42 | private static final PortNumber INTF1_PORT = PortNumber.portNumber(0); |
| 43 | private static final String INTF1_NAME = "FastEthernet0/0"; |
| 44 | private static final PortNumber INTF2_PORT = PortNumber.portNumber(0); |
| 45 | private static final String INTF2_NAME = "Ethernet1/0"; |
| 46 | private static final PortNumber INTF3_PORT = PortNumber.portNumber(0); |
| 47 | private static final String INTF3_NAME = "GigabitEthernet2/0"; |
| 48 | private static final PortNumber INTF4_PORT = PortNumber.portNumber(0); |
| 49 | private static final String INTF4_NAME = "Serial3/0"; |
| 50 | private static final PortNumber INTF5_PORT = PortNumber.portNumber(0); |
| 51 | private static final String INTF5_NAME = "POS4/0"; |
| 52 | private static final PortNumber INTF6_PORT = PortNumber.portNumber(0); |
| 53 | private static final String INTF6_NAME = "Fddi5/0"; |
| 54 | private static final Port.Type COPPER = Port.Type.COPPER; |
| 55 | private static final Port.Type FIBER = Port.Type.FIBER; |
| 56 | private static final long CONNECTION_SPEED_ETHERNET = 100000; |
| 57 | private static final long CONNECTION_SPEED_SERIAL = 1544; |
| 58 | private static final long CONNECTION_SPEED_POS = 9952000; |
| 59 | private static final long CONNECTION_SPEED_FDDI = 100000; |
| 60 | private static final boolean IS_ENABLED = true; |
| 61 | private static final boolean IS_NOT_ENABLED = false; |
| 62 | private static final String TEXT_FILE = "/CiscoIosInterfaces.xml"; |
| 63 | |
| 64 | @Test |
| 65 | public void controllersConfig() { |
| 66 | InputStream streamOrig = getClass().getResourceAsStream(TEXT_FILE); |
| 67 | String rpcReply = new Scanner(streamOrig, "UTF-8").useDelimiter("\\Z").next(); |
| 68 | List<PortDescription> actualIntfs = TextBlockParserCisco.parseCiscoIosPorts(rpcReply); |
| 69 | assertEquals("Interfaces were not retrieved from configuration", |
| 70 | getExpectedIntfs(), actualIntfs); |
| 71 | } |
| 72 | |
| 73 | private List<PortDescription> getExpectedIntfs() { |
| 74 | DefaultAnnotations.Builder int1Annotations = DefaultAnnotations.builder() |
| 75 | .set(AnnotationKeys.PORT_NAME, INTF1_NAME); |
| 76 | DefaultAnnotations.Builder int2Annotations = DefaultAnnotations.builder() |
| 77 | .set(AnnotationKeys.PORT_NAME, INTF2_NAME); |
| 78 | DefaultAnnotations.Builder int3Annotations = DefaultAnnotations.builder() |
| 79 | .set(AnnotationKeys.PORT_NAME, INTF3_NAME); |
| 80 | DefaultAnnotations.Builder int4Annotations = DefaultAnnotations.builder() |
| 81 | .set(AnnotationKeys.PORT_NAME, INTF4_NAME); |
| 82 | DefaultAnnotations.Builder int5Annotations = DefaultAnnotations.builder() |
| 83 | .set(AnnotationKeys.PORT_NAME, INTF5_NAME); |
| 84 | DefaultAnnotations.Builder int6Annotations = DefaultAnnotations.builder() |
| 85 | .set(AnnotationKeys.PORT_NAME, INTF6_NAME); |
| 86 | |
| 87 | List<PortDescription> intfs = new ArrayList<>(); |
| 88 | intfs.add(new DefaultPortDescription(INTF1_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET, |
| 89 | int1Annotations.build())); |
| 90 | intfs.add(new DefaultPortDescription(INTF2_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET, |
| 91 | int2Annotations.build())); |
| 92 | intfs.add(new DefaultPortDescription(INTF3_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET, |
| 93 | int3Annotations.build())); |
| 94 | intfs.add(new DefaultPortDescription(INTF4_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_SERIAL, |
| 95 | int4Annotations.build())); |
| 96 | intfs.add(new DefaultPortDescription(INTF5_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_POS, |
| 97 | int5Annotations.build())); |
| 98 | intfs.add(new DefaultPortDescription(INTF6_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_FDDI, |
| 99 | int6Annotations.build())); |
| 100 | return intfs; |
| 101 | } |
| 102 | } |