8b6135b451d8bd3fe6ddde5bc6dd91f3133b412b
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / util / FlowCreatorUtilTest.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.openflowplugin.openflow.md.util;
9
10 import static junit.framework.Assert.assertTrue;
11 import static junit.framework.TestCase.assertEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregate;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
24
25 public class FlowCreatorUtilTest {
26
27     private static final MacAddress macAddress = new MacAddress("00:00:00:00:00:00");
28     private static final Ipv4Address ipv4Address = new Ipv4Address("0.0.0.0");
29
30     /**
31      * Test method for {@link FlowCreatorUtil#setWildcardedFlowMatch(short version, MultipartRequestFlowBuilder flowBuilder)}.
32      */
33     @Test
34     public void testSetWildcardedFlowMatch_1_0() {
35         MultipartRequestFlowBuilder multipartRequestFlowBuilder = new MultipartRequestFlowBuilder();
36         FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_0, multipartRequestFlowBuilder);
37         MultipartRequestFlow multipartRequestFlow = multipartRequestFlowBuilder.build();
38         assertMatch(multipartRequestFlow.getMatchV10());
39
40         multipartRequestFlowBuilder = new MultipartRequestFlowBuilder();
41         FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_3, multipartRequestFlowBuilder);
42         multipartRequestFlow = multipartRequestFlowBuilder.build();
43         assertMatch(multipartRequestFlow.getMatch());
44     }
45
46     /**
47      * Test method for {@link FlowCreatorUtil#setWildcardedFlowMatch(short version, MultipartRequestAggregateBuilder aggregateBuilder)}.
48      */
49     @Test
50     public void testSetWildcardedFlowMatch_() {
51         MultipartRequestAggregateBuilder multipartRequestAggregateBuilder = new MultipartRequestAggregateBuilder();
52         FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_0, multipartRequestAggregateBuilder);
53         MultipartRequestAggregate multipartRequestAggregate = multipartRequestAggregateBuilder.build();
54         assertMatch(multipartRequestAggregate.getMatchV10());
55
56         multipartRequestAggregateBuilder = new MultipartRequestAggregateBuilder();
57         FlowCreatorUtil.setWildcardedFlowMatch(OFConstants.OFP_VERSION_1_3, multipartRequestAggregateBuilder);
58         multipartRequestAggregate = multipartRequestAggregateBuilder.build();
59         assertMatch(multipartRequestAggregate.getMatch());
60
61
62     }
63
64     private void assertMatch(Match match) {
65         assertTrue(match.getType().getClass().isInstance(OxmMatchType.class));
66     }
67
68     private void assertMatch(MatchV10 matchV10) {
69         assertEquals(matchV10.getDlDst(), macAddress);
70         assertEquals(matchV10.getDlSrc(), macAddress);
71
72         assertTrue(matchV10.getNwSrcMask().shortValue() == 0);
73         assertTrue(matchV10.getNwDstMask().shortValue() == 0);
74
75         assertTrue(matchV10.getInPort().intValue() == 0);
76         assertTrue(matchV10.getDlVlan().intValue() == 0);
77         assertTrue(matchV10.getDlVlanPcp().shortValue() == 0);
78         assertTrue(matchV10.getDlType().intValue() == 0);
79
80         assertTrue(matchV10.getNwTos().shortValue() == 0);
81         assertTrue(matchV10.getNwProto().shortValue() == 0);
82
83         assertEquals(matchV10.getNwSrc(), ipv4Address);
84         assertEquals(matchV10.getNwDst(), ipv4Address);
85
86         assertTrue(matchV10.getTpSrc().intValue() == 0);
87         assertTrue(matchV10.getTpDst().intValue() == 0);
88     }
89
90 }