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;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
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;
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;
34 public class ClassifierTest {
36 List<MatchBuilder> matches;
37 Map<String, ParameterValue> params;
41 matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
42 params = new HashMap<>();
46 public void testUpdateMatch() {
47 Long dstRangeStart = 8079L;
48 Long dstRangeEnd = 8081L;
49 Long singlePort = 80L;
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));
58 ClassificationResult result = Classifier.L4_CL.updateMatch(matches, params);
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()
71 for (Long dstPort = dstRangeStart; dstPort <= dstRangeEnd; dstPort++) {
72 assertTrue(dstPorts.contains(dstPort));