External api proposal
[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  * Contributor: usha.m.s@ericsson.com
9  */
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
11
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
28 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;
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.PortsBuilder;
30
31 public class PortConvertorTest {
32
33     /** defautl mac address */
34     private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
35
36     private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
37             null, null, null, null, null);
38     
39     private PortConfig config = new PortConfig(false, false, false, false);
40     
41     private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures portf31= 
42             new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures(
43                     null, null, null, null, null, null, null, null, null, null, true, null, null, null, null, null);
44     
45     private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig config31 = 
46             new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
47                     false, false, false, false);
48
49     /**
50      * test of {@link PortConvertor#toPortModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port, short)}
51      */
52     @Test
53     public void testtoPortModInputwithAllParameters()
54     {
55         
56         PortBuilder portBld = new PortBuilder();
57         portBld.setAdvertisedFeatures(features);
58         portBld.setConfiguration(config);
59         portBld.setPortNumber(new PortNumberUni(42L));
60         portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
61         
62         PortModInput portOut = PortConvertor.toPortModInput(portBld.build(), EncodeConstants.OF13_VERSION_ID);
63         
64         PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
65         
66         PortModInputBuilder portModInputBld = new PortModInputBuilder();
67         
68         portModInputBld.setConfig(config31);
69         portModInputBld.setMask(config31);
70         portModInputBld.setPortNo(
71                 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
72         portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
73         portModInputBld.setAdvertise(portf31);
74         
75         portModInputBld.setConfigV10(portConfV10);
76         portModInputBld.setMaskV10(portConfV10);
77         portModInputBld.setAdvertiseV10(
78                 new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));
79         
80         portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
81         
82         Assert.assertEquals(portModInputBld.build(), portOut);
83     }
84     
85     /**
86      * test of {@link PortConvertor#toPortDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort , short)}
87      */
88     @Test
89     public void testtoPortDescwithAllParameters(){
90         
91         State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
92         PortState state31= new PortState(false, false, false);
93         
94         FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
95         
96         flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
97         flowCapableNodeConnectorBuilder.setConfiguration(config);
98         flowCapableNodeConnectorBuilder.setCurrentFeature(features);
99         flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
100         flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
101         flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
102         flowCapableNodeConnectorBuilder.setName("foo");
103         flowCapableNodeConnectorBuilder.setPeerFeatures(features);
104         flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L));
105         flowCapableNodeConnectorBuilder.setState(state);
106         flowCapableNodeConnectorBuilder.setSupported(features);
107         
108         Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
109         
110         PortsBuilder portsB = new PortsBuilder();
111         
112         portsB.setAdvertisedFeatures(portf31);
113         portsB.setConfig(config31);
114         portsB.setCurrentFeatures(portf31);
115         portsB.setCurrSpeed(null);
116         portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
117         portsB.setMaxSpeed(null);
118         portsB.setName("foo");
119         portsB.setPeerFeatures(portf31);
120         portsB.setPortNo(42L);
121         portsB.setState(state31);
122         portsB.setSupportedFeatures(portf31);
123         
124         Assert.assertEquals(portsB.build(), portsOut);
125     }
126     
127 }