hiroki | eec31ef | 2018-05-21 07:34:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.drivers.odtn; |
| 17 | |
| 18 | import com.google.common.io.CharSource; |
| 19 | import java.io.IOException; |
| 20 | import java.util.List; |
| 21 | import org.apache.commons.configuration.ConfigurationException; |
| 22 | import org.apache.commons.configuration.XMLConfiguration; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.net.device.PortDescription; |
| 25 | import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery; |
| 26 | |
| 27 | import static org.hamcrest.Matchers.hasSize; |
| 28 | import static org.hamcrest.Matchers.is; |
| 29 | import static org.junit.Assert.assertThat; |
| 30 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME; |
| 31 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_TYPE; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 32 | import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE; |
hiroki | eec31ef | 2018-05-21 07:34:25 -0700 | [diff] [blame] | 33 | |
| 34 | public class InfineraOpenConfigDeviceDiscoveryTest { |
| 35 | |
| 36 | @Test |
| 37 | public void testToPortDescription() throws ConfigurationException, IOException { |
| 38 | // CHECKSTYLE:OFF |
| 39 | String input = |
| 40 | "<data>\n" + |
| 41 | " <interfaces xmlns=\"http://openconfig.net/yang/interfaces\">\n" + |
| 42 | " <interface>\n" + |
| 43 | " <name>CARRIERCTP.1-L1-1</name>\n" + |
| 44 | " <config>\n" + |
| 45 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 46 | " <name>CARRIERCTP.1-L1-1</name>\n" + |
| 47 | " <description/>\n" + |
| 48 | " <enabled>true</enabled>\n" + |
| 49 | " </config>\n" + |
| 50 | " </interface>\n" + |
| 51 | " <interface>\n" + |
| 52 | " <name>CARRIERCTP.1-L1-2</name>\n" + |
| 53 | " <config>\n" + |
| 54 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 55 | " <name>CARRIERCTP.1-L1-2</name>\n" + |
| 56 | " <description/>\n" + |
| 57 | " <enabled>true</enabled>\n" + |
| 58 | " </config>\n" + |
| 59 | " </interface>\n" + |
| 60 | " <interface>\n" + |
| 61 | " <name>CARRIERCTP.1-L1-3</name>\n" + |
| 62 | " <config>\n" + |
| 63 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 64 | " <name>CARRIERCTP.1-L1-3</name>\n" + |
| 65 | " <description/>\n" + |
| 66 | " <enabled>true</enabled>\n" + |
| 67 | " </config>\n" + |
| 68 | " </interface>\n" + |
| 69 | " <interface>\n" + |
| 70 | " <name>CARRIERCTP.1-L1-4</name>\n" + |
| 71 | " <config>\n" + |
| 72 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 73 | " <name>CARRIERCTP.1-L1-4</name>\n" + |
| 74 | " <description/>\n" + |
| 75 | " <enabled>true</enabled>\n" + |
| 76 | " </config>\n" + |
| 77 | " </interface>\n" + |
| 78 | " <interface>\n" + |
| 79 | " <name>CARRIERCTP.1-L1-5</name>\n" + |
| 80 | " <config>\n" + |
| 81 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 82 | " <name>CARRIERCTP.1-L1-5</name>\n" + |
| 83 | " <description/>\n" + |
| 84 | " <enabled>true</enabled>\n" + |
| 85 | " </config>\n" + |
| 86 | " </interface>\n" + |
| 87 | " <interface>\n" + |
| 88 | " <name>CARRIERCTP.1-L1-6</name>\n" + |
| 89 | " <config>\n" + |
| 90 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 91 | " <name>CARRIERCTP.1-L1-6</name>\n" + |
| 92 | " <description/>\n" + |
| 93 | " <enabled>true</enabled>\n" + |
| 94 | " </config>\n" + |
| 95 | " </interface>\n" + |
| 96 | " <interface>\n" + |
| 97 | " <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + |
| 98 | " <config>\n" + |
| 99 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 100 | " <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + |
| 101 | " <description/>\n" + |
| 102 | " <enabled>true</enabled>\n" + |
| 103 | " </config>\n" + |
| 104 | " </interface>\n" + |
| 105 | " <interface>\n" + |
| 106 | " <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + |
| 107 | " <config>\n" + |
| 108 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 109 | " <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + |
| 110 | " <description/>\n" + |
| 111 | " <enabled>true</enabled>\n" + |
| 112 | " </config>\n" + |
| 113 | " </interface>\n" + |
| 114 | " <interface>\n" + |
| 115 | " <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + |
| 116 | " <config>\n" + |
| 117 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 118 | " <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + |
| 119 | " <description/>\n" + |
| 120 | " <enabled>true</enabled>\n" + |
| 121 | " </config>\n" + |
| 122 | " </interface>\n" + |
| 123 | " <interface>\n" + |
| 124 | " <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + |
| 125 | " <config>\n" + |
| 126 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 127 | " <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + |
| 128 | " <description/>\n" + |
| 129 | " <enabled>true</enabled>\n" + |
| 130 | " </config>\n" + |
| 131 | " </interface>\n" + |
| 132 | " <interface>\n" + |
| 133 | " <name>NCTGIGE.1-NCT-1</name>\n" + |
| 134 | " <config>\n" + |
| 135 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + |
| 136 | " <name>NCTGIGE.1-NCT-1</name>\n" + |
| 137 | " <description/>\n" + |
| 138 | " <enabled>true</enabled>\n" + |
| 139 | " </config>\n" + |
| 140 | " </interface>\n" + |
| 141 | " <interface>\n" + |
| 142 | " <name>NCTGIGE.1-NCT-2</name>\n" + |
| 143 | " <config>\n" + |
| 144 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + |
| 145 | " <name>NCTGIGE.1-NCT-2</name>\n" + |
| 146 | " <description/>\n" + |
| 147 | " <enabled>true</enabled>\n" + |
| 148 | " </config>\n" + |
| 149 | " </interface>\n" + |
| 150 | " <interface>\n" + |
| 151 | " <name>OCHCTP.1-L1-1</name>\n" + |
| 152 | " <config>\n" + |
| 153 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 154 | " <name>OCHCTP.1-L1-1</name>\n" + |
| 155 | " <description/>\n" + |
| 156 | " <enabled>true</enabled>\n" + |
| 157 | " </config>\n" + |
| 158 | " </interface>\n" + |
| 159 | " <interface>\n" + |
| 160 | " <name>SCHCTP.1-L1-1</name>\n" + |
| 161 | " <config>\n" + |
| 162 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 163 | " <name>SCHCTP.1-L1-1</name>\n" + |
| 164 | " <description/>\n" + |
| 165 | " <enabled>true</enabled>\n" + |
| 166 | " </config>\n" + |
| 167 | " </interface>\n" + |
| 168 | " <interface>\n" + |
| 169 | " <name>TRIBPTP.1-A-2-T1</name>\n" + |
| 170 | " <config>\n" + |
| 171 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 172 | " <name>TRIBPTP.1-A-2-T1</name>\n" + |
| 173 | " <description/>\n" + |
| 174 | " <enabled>true</enabled>\n" + |
| 175 | " </config>\n" + |
| 176 | " </interface>\n" + |
| 177 | " <interface>\n" + |
| 178 | " <name>TRIBPTP.1-A-2-T2</name>\n" + |
| 179 | " <config>\n" + |
| 180 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 181 | " <name>TRIBPTP.1-A-2-T2</name>\n" + |
| 182 | " <description/>\n" + |
| 183 | " <enabled>true</enabled>\n" + |
| 184 | " </config>\n" + |
| 185 | " </interface>\n" + |
| 186 | " <interface>\n" + |
| 187 | " <name>XTSCGPTP.1-L1</name>\n" + |
| 188 | " <config>\n" + |
| 189 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + |
| 190 | " <name>XTSCGPTP.1-L1</name>\n" + |
| 191 | " <description/>\n" + |
| 192 | " <enabled>true</enabled>\n" + |
| 193 | " </config>\n" + |
| 194 | " </interface>\n" + |
| 195 | " </interfaces>\n" + |
| 196 | "</data>\n"; |
| 197 | // CHECKSTYLE:ON |
| 198 | |
| 199 | InfineraOpenConfigDeviceDiscovery sut = new InfineraOpenConfigDeviceDiscovery(); |
| 200 | |
| 201 | XMLConfiguration cfg = new XMLConfiguration(); |
| 202 | cfg.load(CharSource.wrap(input).openStream()); |
| 203 | |
| 204 | List<PortDescription> ports = sut.discoverPorts(cfg); |
| 205 | |
| 206 | assertThat(ports, hasSize(4)); |
| 207 | |
| 208 | PortDescription portDescription; |
| 209 | portDescription = ports.get(0); |
| 210 | assertThat(portDescription.portNumber().toLong(), is(1L)); |
| 211 | assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-A-2-T1")); |
| 212 | assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-A-2-T1")); |
| 213 | assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-A-2-T1")); |
| 214 | assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), |
| 215 | is(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value())); |
| 216 | |
| 217 | portDescription = ports.get(3); |
| 218 | assertThat(portDescription.portNumber().toLong(), is(102L)); |
| 219 | assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-L2-1-1")); |
| 220 | assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-L2-1-1")); |
| 221 | assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-L2-1-1")); |
| 222 | assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), |
| 223 | is(OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value())); |
| 224 | } |
| 225 | } |