1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
3 import static org.junit.Assert.assertEquals;
5 import java.util.ArrayList;
6 import java.util.HashMap;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
14 import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
15 import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
16 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
21 import com.google.common.collect.ImmutableMap;
23 public class EtherTypeClassifierTest {
26 public ExpectedException thrown = ExpectedException.none();
28 List<MatchBuilder> matches;
29 Map<String, ParameterValue> params;
33 matches = new ArrayList<>();
34 params = new HashMap<>();
38 public void setValueTest() {
39 matches.add(new MatchBuilder().setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
40 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
42 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
44 ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
45 assertEquals(true, ClassifierTestUtils.TCP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
49 public void overrideByTheSameValueTest() {
50 matches.add(new MatchBuilder().setEthernetMatch(
51 ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)).setIpMatch(
52 ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
53 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
55 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
57 ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
58 assertEquals(true, ClassifierTestUtils.UDP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
62 public void overrideByDifferentValueTest() {
63 matches.add(new MatchBuilder().setEthernetMatch(
64 ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)).setIpMatch(
65 ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
66 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
68 thrown.expect(IllegalArgumentException.class);
69 thrown.expectMessage("Classification conflict detected");
70 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
74 public void checkPresenceOfRequiredParameters1Test() {
75 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
76 ClassifierTestUtils.TCP));
77 thrown.expect(IllegalArgumentException.class);
78 thrown.expectMessage("not specified.");
79 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
83 public void checkPresenceOfRequiredParameters2Test() {
84 params.putAll(ImmutableMap.<String, ParameterValue>of(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
85 new ParameterValueBuilder().build()));
86 thrown.expect(IllegalArgumentException.class);
87 thrown.expectMessage("Value of ethertype parameter is not present");
88 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);