2 * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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.openflow.md.core.sal.convertor;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder;
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.PortFeaturesV10;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
29 public class PortConvertorTest {
31 /** defautl mac address */
32 private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
34 private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
35 null, null, null, null, null);
37 private PortConfig config = new PortConfig(false, false, false, false);
39 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures portf31=
40 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures(
41 null, null, null, null, null, null, null, null, null, null, true, null, null, null, null, null);
43 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig config31 =
44 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
45 false, false, false, false);
48 * test of {@link PortConvertor#toPortModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port, short)}
51 public void testtoPortModInputwithAllParameters()
54 PortBuilder portBld = new PortBuilder();
55 portBld.setAdvertisedFeatures(features);
56 portBld.setConfiguration(config);
57 portBld.setPortNumber(new PortNumberUni(42L));
58 portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
60 PortModInput portOut = PortConvertor.toPortModInput(portBld.build(), EncodeConstants.OF13_VERSION_ID);
62 PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
64 PortModInputBuilder portModInputBld = new PortModInputBuilder();
66 portModInputBld.setConfig(config31);
67 portModInputBld.setMask(config31);
68 portModInputBld.setPortNo(
69 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
70 portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
71 portModInputBld.setAdvertise(portf31);
73 portModInputBld.setConfigV10(portConfV10);
74 portModInputBld.setMaskV10(portConfV10);
75 portModInputBld.setAdvertiseV10(
76 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
78 portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
80 Assert.assertEquals(portModInputBld.build(), portOut);
84 * test of {@link PortConvertor#toPortDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort , short)}
87 public void testtoPortDescwithAllParameters(){
89 State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
90 PortState state31= new PortState(false, false, false);
92 FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
94 flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
95 flowCapableNodeConnectorBuilder.setConfiguration(config);
96 flowCapableNodeConnectorBuilder.setCurrentFeature(features);
97 flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
98 flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
99 flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
100 flowCapableNodeConnectorBuilder.setName("foo");
101 flowCapableNodeConnectorBuilder.setPeerFeatures(features);
102 flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L));
103 flowCapableNodeConnectorBuilder.setState(state);
104 flowCapableNodeConnectorBuilder.setSupported(features);
106 Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
108 PortsBuilder portsB = new PortsBuilder();
110 portsB.setAdvertisedFeatures(portf31);
111 portsB.setConfig(config31);
112 portsB.setCurrentFeatures(portf31);
113 portsB.setCurrSpeed(null);
114 portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
115 portsB.setMaxSpeed(null);
116 portsB.setName("foo");
117 portsB.setPeerFeatures(portf31);
118 portsB.setPortNo(42L);
119 portsB.setState(state31);
120 portsB.setSupportedFeatures(portf31);
122 Assert.assertEquals(portsB.build(), portsOut);