Fix fileEncoding violations for checkstyle
[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.assertEquals;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
26 import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
27 import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
28 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
33
34 public class ClassifierTest {
35
36     List<MatchBuilder> matches;
37     Map<String, ParameterValue> params;
38
39     @Before
40     public void init() {
41         matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
42         params = new HashMap<>();
43     }
44
45     @Test
46     public void testUpdateMatch() {
47         Long dstRangeStart = 8079L;
48         Long dstRangeEnd = 8081L;
49         Long singlePort = 80L;
50         params.putAll(
51                 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
52         params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
53                 ClassifierTestUtils.TCP));
54         params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, singlePort));
55         params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
56                 dstRangeStart, dstRangeEnd));
57
58         ClassificationResult result = Classifier.L4_CL.updateMatch(matches, params);
59
60         assertEquals(true, result.isSuccessfull());
61         assertEquals(3, result.getMatchBuilders().size());
62         Set<Long> dstPorts = new HashSet<>();
63         for (MatchBuilder match : result.getMatchBuilders()) {
64             assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, match.getEthernetMatch().getEthernetType());
65             assertSame(singlePort.intValue(),
66                     new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort().getValue());
67             dstPorts.add(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
68                 .getValue()
69                 .longValue());
70         }
71         for (Long dstPort = dstRangeStart; dstPort <= dstRangeEnd; dstPort++) {
72             assertTrue(dstPorts.contains(dstPort));
73         }
74     }
75 }