Merge "Fix SwitchIdleEvent echo request-reply xid"
[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.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;
31
32 public class PortConvertorTest {
33
34     /** defautl mac address */
35     private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
36
37     private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
38             null, null, null, null, null);
39
40     private PortConfig config = new PortConfig(false, false, false, false);
41
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);
45
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);
49
50     /**
51      * 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)} }
52      */
53     @Test
54     public void testtoPortModInputwithAllParameters()
55     {
56
57         PortBuilder portBld = new PortBuilder();
58         portBld.setAdvertisedFeatures(features);
59         portBld.setConfiguration(config);
60         portBld.setPortNumber(new PortNumberUni(42L));
61         portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
62
63         VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
64         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
65         Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
66         PortModInput portOut = portOutOptional.orElse(PortConvertor.defaultResult(OFConstants.OFP_VERSION_1_3));
67
68         PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
69
70         PortModInputBuilder portModInputBld = new PortModInputBuilder();
71
72         portModInputBld.setConfig(config31);
73         portModInputBld.setMask(config31);
74         portModInputBld.setPortNo(
75                 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
76         portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
77         portModInputBld.setAdvertise(portf31);
78
79         portModInputBld.setConfigV10(portConfV10);
80         portModInputBld.setMaskV10(portConfV10);
81         portModInputBld.setAdvertiseV10(
82                 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
83
84         portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
85
86         Assert.assertEquals(portModInputBld.build(), portOut);
87     }
88
89     /**
90      * test of {@link PortConvertor#toPortDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort , short)}
91      */
92     @Test
93     public void testtoPortDescwithAllParameters(){
94
95         State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
96         PortState state31= new PortState(false, false, false);
97
98         FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
99
100         flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
101         flowCapableNodeConnectorBuilder.setConfiguration(config);
102         flowCapableNodeConnectorBuilder.setCurrentFeature(features);
103         flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
104         flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
105         flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
106         flowCapableNodeConnectorBuilder.setName("foo");
107         flowCapableNodeConnectorBuilder.setPeerFeatures(features);
108         flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L));
109         flowCapableNodeConnectorBuilder.setState(state);
110         flowCapableNodeConnectorBuilder.setSupported(features);
111
112         Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
113
114         PortsBuilder portsB = new PortsBuilder();
115
116         portsB.setAdvertisedFeatures(portf31);
117         portsB.setConfig(config31);
118         portsB.setCurrentFeatures(portf31);
119         portsB.setCurrSpeed(null);
120         portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
121         portsB.setMaxSpeed(null);
122         portsB.setName("foo");
123         portsB.setPeerFeatures(portf31);
124         portsB.setPortNo(42L);
125         portsB.setState(state31);
126         portsB.setSupportedFeatures(portf31);
127
128         Assert.assertEquals(portsB.build(), portsOut);
129     }
130
131 }