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 .setPortModOrder(Uint32.ZERO)
64 .setAdvertisedFeatures(features)
65 .setConfiguration(config)
66 .setPortNumber(new PortNumberUni(Uint32.valueOf(42)))
67 .setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
69 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
70 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
71 final Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
72 final PortModInput portOut = portOutOptional
73 .orElse(PortConvertor.defaultResult(EncodeConstants.OF_VERSION_1_3));
75 PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
77 PortModInputBuilder portModInputBld = new PortModInputBuilder();
79 portModInputBld.setConfig(config31);
80 portModInputBld.setMask(configMask31);
81 portModInputBld.setPortNo(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
82 .PortNumber(Uint32.valueOf(42)));
83 portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
84 portModInputBld.setAdvertise(portf31);
86 portModInputBld.setConfigV10(portConfV10);
87 portModInputBld.setMaskV10(portConfMaskV10);
88 portModInputBld.setAdvertiseV10(
89 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
91 portModInputBld.setVersion(EncodeConstants.OF_VERSION_1_3);
93 Assert.assertEquals(portModInputBld.build(), portOut);
97 * test of {@link PortConvertor#toPortDesc(FlowCapablePort , short)}.
100 public void testtoPortDescwithAllParameters() {
102 State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
104 FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
106 flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
107 flowCapableNodeConnectorBuilder.setConfiguration(config);
108 flowCapableNodeConnectorBuilder.setCurrentFeature(features);
109 flowCapableNodeConnectorBuilder.setCurrentSpeed((Uint32) null);
110 flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
111 flowCapableNodeConnectorBuilder.setMaximumSpeed((Uint32) null);
112 flowCapableNodeConnectorBuilder.setName("foo");
113 flowCapableNodeConnectorBuilder.setPeerFeatures(features);
114 flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(Uint32.valueOf(42L)));
115 flowCapableNodeConnectorBuilder.setState(state);
116 flowCapableNodeConnectorBuilder.setSupported(features);
118 final Ports portsOut = PortConvertor.toPortDesc(
119 flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF_VERSION_1_3);
121 PortsBuilder portsB = new PortsBuilder();
123 portsB.setAdvertisedFeatures(portf31);
124 portsB.setConfig(config31);
125 portsB.setCurrentFeatures(portf31);
126 portsB.setCurrSpeed((Uint32) null);
127 portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
128 portsB.setMaxSpeed((Uint32) null);
129 portsB.setName("foo");
130 portsB.setPeerFeatures(portf31);
131 portsB.setPortNo(Uint32.valueOf(42));
132 portsB.setState(new PortState(false, false, false));
133 portsB.setSupportedFeatures(portf31);
135 Assert.assertEquals(portsB.build(), portsOut);