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 java.util.Optional;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
15 import org.opendaylight.openflowplugin.api.OFConstants;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
29 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;
30 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;
32 public class PortConvertorTest {
34 /** defautl mac address */
35 private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
37 private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
38 null, null, null, null, null);
40 private PortConfig config = new PortConfig(false, false, false, false);
42 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures portf31=
43 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures(
44 null, null, null, null, null, null, null, null, null, null, true, null, null, null, null, null);
46 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig config31 =
47 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
48 false, false, false, false);
50 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig configMask31 =
51 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
52 true, true, true, true);
54 private PortConfigV10 portConfMaskV10 = new PortConfigV10(true, true, true, true, true, true, true);;
57 * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)} }
60 public void testtoPortModInputwithAllParameters()
63 PortBuilder portBld = new PortBuilder();
64 portBld.setAdvertisedFeatures(features);
65 portBld.setConfiguration(config);
66 portBld.setPortNumber(new PortNumberUni(42L));
67 portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
69 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
70 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
71 Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
72 PortModInput portOut = portOutOptional.orElse(PortConvertor.defaultResult(OFConstants.OFP_VERSION_1_3));
74 PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
76 PortModInputBuilder portModInputBld = new PortModInputBuilder();
78 portModInputBld.setConfig(config31);
79 portModInputBld.setMask(configMask31);
80 portModInputBld.setPortNo(
81 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
82 portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
83 portModInputBld.setAdvertise(portf31);
85 portModInputBld.setConfigV10(portConfV10);
86 portModInputBld.setMaskV10(portConfMaskV10);
87 portModInputBld.setAdvertiseV10(
88 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
90 portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
92 Assert.assertEquals(portModInputBld.build(), portOut);
96 * test of {@link PortConvertor#toPortDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort , short)}
99 public void testtoPortDescwithAllParameters(){
101 State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
102 PortState state31= new PortState(false, false, false);
104 FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
106 flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
107 flowCapableNodeConnectorBuilder.setConfiguration(config);
108 flowCapableNodeConnectorBuilder.setCurrentFeature(features);
109 flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
110 flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
111 flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
112 flowCapableNodeConnectorBuilder.setName("foo");
113 flowCapableNodeConnectorBuilder.setPeerFeatures(features);
114 flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L));
115 flowCapableNodeConnectorBuilder.setState(state);
116 flowCapableNodeConnectorBuilder.setSupported(features);
118 Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
120 PortsBuilder portsB = new PortsBuilder();
122 portsB.setAdvertisedFeatures(portf31);
123 portsB.setConfig(config31);
124 portsB.setCurrentFeatures(portf31);
125 portsB.setCurrSpeed(null);
126 portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
127 portsB.setMaxSpeed(null);
128 portsB.setName("foo");
129 portsB.setPeerFeatures(portf31);
130 portsB.setPortNo(42L);
131 portsB.setState(state31);
132 portsB.setSupportedFeatures(portf31);
134 Assert.assertEquals(portsB.build(), portsOut);