2 * Copyright (c) 2014 Cisco Systems, Inc. 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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
11 import static org.junit.Assert.*;
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;
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;
27 import org.junit.Before;
28 import org.junit.Test;
30 public class ClassifierTest {
32 List<MatchBuilder> matches;
33 Map<String, ParameterValue> params;
37 matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
38 params = new HashMap<>();
42 public void updateMatchTest() {
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()
59 dstPorts.add(Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
63 for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
64 assertEquals(true, dstPorts.contains((i)));