2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
15 import java.math.BigInteger;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
28 * Created by Martin Bobak mbobak@cisco.com on 7/29/14.
30 public class PortTranslatorUtilTest {
32 private static final String MAC_ADDRESS = "00:01:02:03:04:05";
33 private static final String NAME = "PortTranslatorTest";
34 private final Boolean[] pfBls
35 = {false, false, false, false, false, false, false, false, false, false, false, false, false, false,
37 private final boolean[] pfV10Bls
38 = {false, false, false, false, false, false, false, false, false, false, false, false};
39 private final boolean[] portCfgBools = {false, false, false, false};
40 private final boolean[] portCfgV10bools = {false, false, false, false, false, false, false};
41 private final boolean[] portStateBools = {false, false, false, false};
42 private final Long currentSpeed = Long.decode("4294967295");
43 private static final Long MAX_SPEED = Long.decode("4294967295");
47 * {@link PortTranslatorUtil#translatePortFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight
48 * .openflow.common.types.rev130731.PortFeatures)}.
51 public void testTranslatePortFeatures() {
52 for (int i = 0; i < pfBls.length; i++) {
54 final PortFeatures apf = getPortFeatures();
55 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures npf
56 = PortTranslatorUtil.translatePortFeatures(apf);
57 assertEqualsPortFeatures(apf, npf);
62 private PortFeatures getPortFeatures() {
63 return new PortFeatures(pfBls[0], pfBls[1], pfBls[2], pfBls[3], pfBls[4], pfBls[5], pfBls[6], pfBls[7],
64 pfBls[8], pfBls[9], pfBls[10], pfBls[11], pfBls[12], pfBls[13], pfBls[14], pfBls[15]);
69 * {@link PortTranslatorUtil#translatePortFeatures(org.opendaylight.yang.gen.v1.urn
70 * .opendaylight.openflow.common.types.rev130731.PortFeaturesV10)}.
73 public void testTranslatePortFeaturesV10() {
76 for (int i = 0; i < pfV10Bls.length; i++) {
79 final PortFeaturesV10 apfV10 = getPortFeaturesV10();
80 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures npf
81 = PortTranslatorUtil.translatePortFeatures(apfV10);
82 assertEqualsPortFeaturesV10(apfV10, npf);
89 private PortFeaturesV10 getPortFeaturesV10() {
90 return new PortFeaturesV10(pfV10Bls[0], pfV10Bls[1], pfV10Bls[2], pfV10Bls[3], pfV10Bls[4], pfV10Bls[5],
91 pfV10Bls[6], pfV10Bls[7], pfV10Bls[8], pfV10Bls[9], pfV10Bls[10], pfV10Bls[11]);
96 * {@link PortTranslatorUtil#translatePort(Short, java.math.BigInteger,
97 * Long, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping)} ()}.
100 public void testTranslatePort() {
102 Short version = OpenflowVersion.OF10.getVersion();
104 BigInteger dataPathId = BigInteger.ONE;
105 Long portNumber = Long.MAX_VALUE;
106 PortGrouping portGrouping = mockPortGrouping();
108 NodeConnectorUpdated nodeConnectorUpdated = PortTranslatorUtil
109 .translatePort(version, dataPathId, portNumber, portGrouping);
110 assertNotNull(nodeConnectorUpdated);
111 version = OpenflowVersion.OF13.getVersion();
112 nodeConnectorUpdated = PortTranslatorUtil.translatePort(version, dataPathId, portNumber, portGrouping);
113 assertNotNull(nodeConnectorUpdated);
115 version = OpenflowVersion.UNSUPPORTED.getVersion();
116 nodeConnectorUpdated = PortTranslatorUtil.translatePort(version, dataPathId, portNumber, portGrouping);
117 assertNotNull(nodeConnectorUpdated);
122 private PortGrouping mockPortGrouping() {
123 PortGrouping portGrouping = mock(PortGrouping.class);
124 when(portGrouping.getAdvertisedFeatures()).thenReturn(getPortFeatures());
125 when(portGrouping.getAdvertisedFeaturesV10()).thenReturn(getPortFeaturesV10());
126 when(portGrouping.getConfig()).thenReturn(getPortConfig());
127 when(portGrouping.getConfigV10()).thenReturn(getPortConfigV10());
128 when(portGrouping.getCurrentFeatures()).thenReturn(getPortFeatures());
129 when(portGrouping.getCurrentFeaturesV10()).thenReturn(getPortFeaturesV10());
130 when(portGrouping.getCurrSpeed()).thenReturn(currentSpeed);
131 when(portGrouping.getHwAddr()).thenReturn(getMacAddress());
132 when(portGrouping.getName()).thenReturn(NAME);
133 when(portGrouping.getMaxSpeed()).thenReturn(MAX_SPEED);
134 when(portGrouping.getPeerFeatures()).thenReturn(getPortFeatures());
135 when(portGrouping.getPeerFeaturesV10()).thenReturn(getPortFeaturesV10());
136 when(portGrouping.getPortNo()).thenReturn(Long.MAX_VALUE);
137 when(portGrouping.getState()).thenReturn(getPortState());
138 when(portGrouping.getSupportedFeatures()).thenReturn(getPortFeatures());
139 when(portGrouping.getSupportedFeaturesV10()).thenReturn(getPortFeaturesV10());
143 private PortState getPortState() {
144 PortState portState = new PortState(portStateBools[0], portStateBools[1], portStateBools[2]);
148 private static MacAddress getMacAddress() {
149 return new MacAddress(MAC_ADDRESS);
152 private PortConfigV10 getPortConfigV10() {
153 return new PortConfigV10(portCfgV10bools[0], portCfgV10bools[1], portCfgV10bools[2], portCfgV10bools[3],
154 portCfgV10bools[4], portCfgV10bools[5], portCfgV10bools[6]);
157 private PortConfig getPortConfig() {
158 return new PortConfig(portCfgBools[0], portCfgBools[1], portCfgBools[2], portCfgBools[3]);
161 private static void assertEqualsPortFeaturesV10(final PortFeaturesV10 apfV10,
162 final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types
163 .port.rev130925.PortFeatures npf) {
164 assertEquals(apfV10.is_100mbFd(), npf.isHundredMbFd());
165 assertEquals(apfV10.is_100mbHd(), npf.isHundredMbHd());
167 assertEquals(apfV10.is_10gbFd(), npf.isTenGbFd());
168 assertEquals(apfV10.is_10mbFd(), npf.isTenMbFd());
169 assertEquals(apfV10.is_10mbHd(), npf.isTenMbHd());
171 assertEquals(apfV10.is_1gbFd(), npf.isOneGbFd());
172 assertEquals(apfV10.is_1gbHd(), npf.isOneGbHd());
174 assertEquals(apfV10.isAutoneg(), npf.isAutoeng());
175 assertEquals(apfV10.isCopper(), npf.isCopper());
176 assertEquals(apfV10.isFiber(), npf.isFiber());
177 assertEquals(apfV10.isPause(), npf.isPause());
178 assertEquals(apfV10.isPauseAsym(), npf.isPauseAsym());
181 private static void assertEqualsPortFeatures(final PortFeatures apf,
182 final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port
183 .rev130925.PortFeatures npf) {
184 assertEquals(apf.is_100gbFd(), npf.isHundredGbFd());
185 assertEquals(apf.is_100mbFd(), npf.isHundredMbFd());
186 assertEquals(apf.is_100mbHd(), npf.isHundredMbHd());
188 assertEquals(apf.is_10gbFd(), npf.isTenGbFd());
189 assertEquals(apf.is_10mbFd(), npf.isTenMbFd());
190 assertEquals(apf.is_10mbHd(), npf.isTenMbHd());
192 assertEquals(apf.is_1gbFd(), npf.isOneGbFd());
193 assertEquals(apf.is_1gbHd(), npf.isOneGbHd());
194 assertEquals(apf.is_1tbFd(), npf.isOneTbFd());
196 assertEquals(apf.is_40gbFd(), npf.isFortyGbFd());
198 assertEquals(apf.isAutoneg(), npf.isAutoeng());
199 assertEquals(apf.isCopper(), npf.isCopper());
200 assertEquals(apf.isFiber(), npf.isFiber());
201 assertEquals(apf.isOther(), npf.isOther());
202 assertEquals(apf.isPause(), npf.isPause());
203 assertEquals(apf.isPauseAsym(), npf.isPauseAsym());