1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
3 import static org.junit.Assert.*;
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.renderer.ofoverlay.flow.FlowUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
19 import com.google.common.collect.ImmutableMap;
21 public class EtherTypeClassifierTest {
24 public ExpectedException thrown = ExpectedException.none();
26 List<MatchBuilder> matches;
27 Map<String, ParameterValue> params;
31 matches = new ArrayList<>();
32 params = new HashMap<>();
36 public void setValueTest() {
37 matches.add(new MatchBuilder()
38 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
39 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv4));
40 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
41 assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
42 assertEquals(true, ClassifierTestUtils.TCP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
46 public void overrideByTheSameValueTest() {
47 matches.add(new MatchBuilder()
48 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
49 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
50 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv6));
51 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
52 assertEquals(true, ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
53 assertEquals(true, ClassifierTestUtils.UDP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
57 public void overrideByDifferentValueTest() {
58 matches.add(new MatchBuilder()
59 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
60 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
61 params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv6));
62 thrown.expect(IllegalArgumentException.class);
63 thrown.expectMessage("Trying to override ether-type value:");
64 matches = Classifier.ETHER_TYPE_CL.update(matches, params);
68 public void checkPresenceOfRequiredParameters1Test() {
69 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifier.PROTO, ClassifierTestUtils.TCP));
70 thrown.expect(IllegalArgumentException.class);
71 thrown.expectMessage("Parameter ethertype not present");
72 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
76 public void checkPresenceOfRequiredParameters2Test() {
77 params.putAll(ImmutableMap.<String, ParameterValue> of(EtherTypeClassifier.ETHER_TYPE,
78 new ParameterValueBuilder().build()));
79 thrown.expect(IllegalArgumentException.class);
80 thrown.expectMessage("Value of ethertype parameter is not present");
81 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);