d9d461c17dac9ed395b403b2b9ee01545532050f
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / sf / ClassifierTest.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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
10
11 import static org.junit.Assert.*;
12
13 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30 public class ClassifierTest {
31
32     List<MatchBuilder> matches;
33     Map<String, ParameterValue> params;
34
35     @Before
36     public void setUp() {
37         matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
38         params = new HashMap<>();
39     }
40
41     @Test
42     public void updateMatchTest() {
43
44         Long dstRangeStart = Long.valueOf(8079);
45         Long dstRangeEnd = Long.valueOf(8081);
46         params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv4));
47         params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifier.PROTO, ClassifierTestUtils.TCP));
48         params.putAll(ClassifierTestUtils.createIntValueParam(L4Classifier.SPORT, 80));
49         params.putAll(ClassifierTestUtils.createRangeValueParam(L4Classifier.DPORT_RANGE, dstRangeStart, dstRangeEnd));
50         ClassificationResult result = Classifier.L4_CL.updateMatch(matches, params);
51         assertEquals(true, result.isSuccessfull());
52         assertEquals(3, result.getMatchBuilders().size());
53         Set<Long> dstPorts = new HashSet<>();
54         for (MatchBuilder match : result.getMatchBuilders()) {
55             assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
56             assertEquals(true, new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort()
57                 .getValue()
58                 .intValue() == 80);
59             dstPorts.add(Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
60                 .getValue()
61                 .longValue()));
62         }
63         for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
64             assertEquals(true, dstPorts.contains((i)));
65         }
66     }
67 }