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 * Contributor: usha.m.s@ericsson.com
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
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.CommonPort.PortNumber;
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.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;
31 public class PortConvertorTest {
33 /** defautl mac address */
34 private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
36 private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
37 null, null, null, null, null);
39 private PortConfig config = new PortConfig(false, false, false, false);
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);
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);
50 * test of {@link PortConvertor#toPortModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port, short)}
53 public void testtoPortModInputwithAllParameters()
56 PortBuilder portBld = new PortBuilder();
57 portBld.setAdvertisedFeatures(features);
58 portBld.setConfiguration(config);
59 portBld.setPortNumber(new PortNumber(42L));
60 portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
62 PortModInput portOut = PortConvertor.toPortModInput(portBld.build(), EncodeConstants.OF13_VERSION_ID);
64 PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);
66 PortModInputBuilder portModInputBld = new PortModInputBuilder();
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);
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));
80 portModInputBld.setVersion((short) EncodeConstants.OF13_VERSION_ID);
82 Assert.assertEquals(portModInputBld.build(), portOut);
86 * test of {@link PortConvertor#toPortDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort , short)}
89 public void testtoPortDescwithAllParameters(){
91 State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
92 PortState state31= new PortState(false, false, false);
94 FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
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 PortNumber(42L));
105 flowCapableNodeConnectorBuilder.setState(state);
106 flowCapableNodeConnectorBuilder.setSupported(features);
108 Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
110 PortsBuilder portsB = new PortsBuilder();
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);
124 Assert.assertEquals(portsB.build(), portsOut);