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.assertEquals;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.List;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
24 import org.opendaylight.groupbasedpolicy.sf.classifiers.EtherTypeClassifierDefinition;
25 import org.opendaylight.groupbasedpolicy.sf.classifiers.IpProtoClassifierDefinition;
26 import org.opendaylight.groupbasedpolicy.sf.classifiers.L4ClassifierDefinition;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
32 public class ClassifierTest {
34 List<MatchBuilder> matches;
35 Map<String, ParameterValue> params;
39 matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
40 params = new HashMap<>();
44 public void updateMatchTest() {
45 Long dstRangeStart = Long.valueOf(8079);
46 Long dstRangeEnd = Long.valueOf(8081);
47 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
49 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
50 ClassifierTestUtils.TCP));
51 params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, 80));
52 params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
53 dstRangeStart, dstRangeEnd));
54 ClassificationResult result = Classifier.L4_CL.updateMatch(matches, params);
55 assertEquals(true, result.isSuccessfull());
56 assertEquals(3, result.getMatchBuilders().size());
57 Set<Long> dstPorts = new HashSet<>();
58 for (MatchBuilder match : result.getMatchBuilders()) {
59 assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
60 assertEquals(true, new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort()
63 dstPorts.add(Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
67 for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
68 assertEquals(true, dstPorts.contains((i)));