Enable AD-SAL application to configure OF 1.3 PUSH_VLAN action.
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / test / java / org / opendaylight / controller / sal / compatibility / test / MDFlowMappingTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.compatibility.test;
9
10 import junit.framework.Assert;
11
12 import org.junit.Test;
13 import org.opendaylight.controller.sal.action.Action;
14 import org.opendaylight.controller.sal.action.PushVlan;
15 import org.opendaylight.controller.sal.compatibility.MDFlowMapping;
16 import org.opendaylight.controller.sal.core.ConstructionException;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.core.Node.NodeIDType;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
21 import org.opendaylight.controller.sal.utils.EtherTypes;
22
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
25
26 /**
27  * test for {@link MDFlowMapping}
28  */
29 public class MDFlowMappingTest {
30
31     /**
32      * Test method for {@link org.opendaylight.controller.sal.compatibility.MDFlowMapping#toUri(org.opendaylight.controller.sal.core.NodeConnector)}.
33      * @throws ConstructionException
34      */
35     @Test
36     public void testToUri() throws ConstructionException {
37         Node node = new Node(NodeIDType.OPENFLOW, 41L);
38         NodeConnector connector = new NodeConnector(NodeConnectorIDType.OPENFLOW, (short) 42, node);
39         Uri observed = MDFlowMapping.toUri(connector );
40
41         Assert.assertEquals("openflow:41:42", observed.getValue());
42     }
43
44     /**
45      * Test method for {@link MDFlowMapping#toAction(Action, int)}.
46      */
47     @Test
48     public void testToAction() {
49         // PUSH_VLAN test.
50         EtherTypes[] tags = {EtherTypes.VLANTAGGED, EtherTypes.QINQ};
51         int order = 0;
52         for (EtherTypes tag: tags) {
53             Action action = new PushVlan(tag);
54             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
55                 rev131112.action.list.Action mdActionList =
56                 MDFlowMapping.toAction(action, order);
57             Assert.assertEquals(order, mdActionList.getOrder().intValue());
58
59             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
60                 rev131112.action.Action mdAction = mdActionList.getAction();
61             Assert.assertTrue(mdAction instanceof PushVlanActionCase);
62             PushVlanActionCase pushVlan = (PushVlanActionCase)mdAction;
63             Assert.assertEquals(tag.intValue(),
64                                 pushVlan.getPushVlanAction().getEthernetType().
65                                 intValue());
66             order++;
67         }
68     }
69 }