blob: 4b2e1c45e9c3ab4da9fac9c7badfab063087c6be [file] [log] [blame]
Yuta HIGUCHI8c6e1942018-04-05 13:40:51 -07001/*
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 */
16package org.onosproject.drivers.odtn;
17
18import static org.hamcrest.Matchers.hasSize;
19import static org.hamcrest.Matchers.is;
20import static org.junit.Assert.assertThat;
21import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
22import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_TYPE;
23
24import java.io.IOException;
25import java.util.List;
26import org.apache.commons.configuration.ConfigurationException;
27import org.apache.commons.configuration.XMLConfiguration;
28import org.junit.Test;
29import org.onosproject.net.device.PortDescription;
30import com.google.common.io.CharSource;
31
32public class OpenConfigDeviceDiscoveryTest {
33
34 @Test
35 public void testToPortDescription() throws ConfigurationException, IOException {
36 // CHECKSTYLE:OFF
37 String input =
38 "<data>\n" +
39 "<components xmlns=\"http://openconfig.net/yang/platform\">\n" +
40 "\n" +
41 " <component>\n" +
42 " <name>TPC_1_1_4_N2_200G</name>\n" +
43 " <config>\n" +
44 " <name>TPC_1_1_4_N2_200G</name>\n" +
45 " </config>\n" +
46 " <state>\n" +
47 " <name>TPC_1_1_4_N2_200G</name>\n" +
48 " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:LINECARD</type>\n" +
49 " </state>\n" +
50 " </component>\n" +
51 "\n" +
52 " <component>\n" +
53 " <name>CLIPORT_1_1_4_1</name>\n" +
54 " <config>\n" +
55 " <name>CLIPORT_1_1_4_1</name>\n" +
56 " </config>\n" +
57 " <state>\n" +
58 " <name>CLIPORT_1_1_4_1</name>\n" +
59 " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" +
60 " </state>\n" +
61 " </component>\n" +
62 "\n" +
63 " <component>\n" +
64 " <name>LINEPORT_1_1_4</name>\n" +
65 " <config>\n" +
66 " <name>LINEPORT_1_1_4</name>\n" +
67 " </config>\n" +
68 " <state>\n" +
69 " <name>LINEPORT_1_1_4</name>\n" +
70 " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" +
71 " </state>\n" +
72 " </component>\n" +
73 "\n" +
74 " <component>\n" +
75 " <name>TRANSCEIVER_1_1_4_1</name>\n" +
76 " <config>\n" +
77 " <name>TRANSCEIVER_1_1_4_1</name> \n" +
78 " </config>\n" +
79 " <state>\n" +
80 " <name>TRANSCEIVER_1_1_4_1</name>\n" +
81 " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:TRANSCEIVER</type>\n" +
82 " </state>\n" +
83 " <properties>\n" +
84 " <property>\n" +
85 " <name>onos-index</name>\n" +
86 " <config>\n" +
87 " <name>onos-index</name>\n" +
88 " <value>42</value>\n" +
89 " </config>\n" +
90 " </property>\n" +
91 " </properties>\n" +
92 " <transceiver xmlns=\"http://openconfig.net/yang/platform/transceiver\">\n" +
93 " <config>\n" +
94 " <enabled>true</enabled>\n" +
95 " <form-factor-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" +
96 " <ethernet-pmd-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" +
97 " </config>\n" +
98 " <state>\n" +
99 " <enabled>true</enabled>\n" +
100 " <form-factor-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" +
101 " <ethernet-pmd-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" +
102 " </state>\n" +
103 " </transceiver>\n" +
104 " </component>\n" +
105 "\n" +
106 " <component>\n" +
107 " <name>OPTCHANNEL_1_1_4</name>\n" +
108 " <config>\n" +
109 " <name>OPTCHANNEL_1_1_4</name>\n" +
110 " </config>\n" +
111 " <state>\n" +
112 " <name>OPTCHANNEL_1_1_4</name>\n" +
113 " <type xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:OPTICAL_CHANNEL</type>\n" +
114 " </state>\n" +
115 " <optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">\n" +
116 " <config>\n" +
117 " <frequency>191500000</frequency>\n" +
118 " <target-output-power>0.0</target-output-power>\n" +
119 " </config>\n" +
120 " <state>\n" +
121 " <frequency>191500000</frequency>\n" +
122 " <target-output-power>0.0</target-output-power>\n" +
123 " </state>\n" +
124 " </optical-channel>\n" +
125 " </component>\n" +
126 "\n" +
127 "</components>\n" +
128 "</data>";
129 // CHECKSTYLE:ON
130
131 OpenConfigDeviceDiscovery sut = new OpenConfigDeviceDiscovery();
132
133 XMLConfiguration cfg = new XMLConfiguration();
134 cfg.load(CharSource.wrap(input).openStream());
135
136 List<PortDescription> ports = sut.discoverPorts(cfg);
137
138 assertThat(ports, hasSize(1));
139 PortDescription portDescription = ports.get(0);
140 assertThat(portDescription.portNumber().toLong(), is(42L));
141 assertThat(portDescription.portNumber().name(), is("TRANSCEIVER_1_1_4_1"));
142
143
144 assertThat(portDescription.annotations().value(OC_NAME), is("TRANSCEIVER_1_1_4_1"));
145 assertThat(portDescription.annotations().value(OC_TYPE), is("oc-platform-types:TRANSCEIVER"));
146
147 }
148
149}