Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / PortConvertorTest.java
1 /*
2  * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
9
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;
33
34 public class PortConvertorTest {
35
36     private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
37
38     private final PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null,
39             null, null, null, null, null, null);
40
41     private final PortConfig config = new PortConfig(false, false, false, false);
42
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);
46
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);
50
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);
54
55     private final PortConfigV10 portConfMaskV10 = new PortConfigV10(true, true, true, true, true, true, true);
56
57     /**
58      * test of {@link PortConvertor#convert(Port, VersionConvertorData)} }.
59      */
60     @Test
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));
67
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));
72
73         PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
74
75         PortModInputBuilder portModInputBld = new PortModInputBuilder();
76
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);
83
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));
88
89         portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
90
91         Assert.assertEquals(portModInputBld.build(), portOut);
92     }
93
94     /**
95      * test of {@link PortConvertor#toPortDesc(FlowCapablePort , short)}.
96      */
97     @Test
98     public void testtoPortDescwithAllParameters() {
99
100         State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
101
102         FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
103
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);
115
116         final Ports portsOut = PortConvertor.toPortDesc(
117                 flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
118
119         PortsBuilder portsB = new PortsBuilder();
120
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);
132
133         Assert.assertEquals(portsB.build(), portsOut);
134     }
135 }