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.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
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.FlowCapablePort;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
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.Ports;
31 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 import org.opendaylight.yangtools.yang.common.Uint32;
34 public class PortConvertorTest {
36 private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
38 private final PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null,
39 null, null, null, null, null, null);
41 private final PortConfig config = new PortConfig(false, false, false, false);
43 private final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures portf31 =
44 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures(
45 null, null, null, null, null, null, null, null, null, null, true, null, null, null, null, null);
47 private final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig config31 =
48 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
49 false, false, false, false);
51 private final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig
52 configMask31 = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
53 true, true, true, true);
55 private final PortConfigV10 portConfMaskV10 = new PortConfigV10(true, true, true, true, true, true, true);
58 * test of {@link PortConvertor#convert(Port, VersionConvertorData)} }.
61 public void testtoPortModInputwithAllParameters() {
62 PortBuilder portBld = new PortBuilder();
63 portBld.setAdvertisedFeatures(features);
64 portBld.setConfiguration(config);
65 portBld.setPortNumber(new PortNumberUni(Uint32.valueOf(42L)));
66 portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
68 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
69 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
70 Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
71 final PortModInput portOut = portOutOptional.orElse(PortConvertor.defaultResult(OFConstants.OFP_VERSION_1_3));
73 PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
75 PortModInputBuilder portModInputBld = new PortModInputBuilder();
77 portModInputBld.setConfig(config31);
78 portModInputBld.setMask(configMask31);
79 portModInputBld.setPortNo(
80 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
81 portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
82 portModInputBld.setAdvertise(portf31);
84 portModInputBld.setConfigV10(portConfV10);
85 portModInputBld.setMaskV10(portConfMaskV10);
86 portModInputBld.setAdvertiseV10(
87 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
89 portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
91 Assert.assertEquals(portModInputBld.build(), portOut);
95 * test of {@link PortConvertor#toPortDesc(FlowCapablePort , short)}.
98 public void testtoPortDescwithAllParameters() {
100 State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
102 FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
104 flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
105 flowCapableNodeConnectorBuilder.setConfiguration(config);
106 flowCapableNodeConnectorBuilder.setCurrentFeature(features);
107 flowCapableNodeConnectorBuilder.setCurrentSpeed((Uint32) null);
108 flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
109 flowCapableNodeConnectorBuilder.setMaximumSpeed((Uint32) null);
110 flowCapableNodeConnectorBuilder.setName("foo");
111 flowCapableNodeConnectorBuilder.setPeerFeatures(features);
112 flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(Uint32.valueOf(42L)));
113 flowCapableNodeConnectorBuilder.setState(state);
114 flowCapableNodeConnectorBuilder.setSupported(features);
116 final Ports portsOut = PortConvertor.toPortDesc(
117 flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
119 PortsBuilder portsB = new PortsBuilder();
121 portsB.setAdvertisedFeatures(portf31);
122 portsB.setConfig(config31);
123 portsB.setCurrentFeatures(portf31);
124 portsB.setCurrSpeed((Uint32) null);
125 portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
126 portsB.setMaxSpeed((Uint32) null);
127 portsB.setName("foo");
128 portsB.setPeerFeatures(portf31);
129 portsB.setPortNo(42L);
130 portsB.setState(new PortState(false, false, false));
131 portsB.setSupportedFeatures(portf31);
133 Assert.assertEquals(portsB.build(), portsOut);