1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertSame;
6 import java.util.ArrayList;
7 import java.util.HashMap;
11 import com.google.common.collect.ImmutableMap;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.rules.ExpectedException;
15 import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
16 import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
17 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
22 public class EtherTypeClassifierTest {
25 public ExpectedException thrown = ExpectedException.none();
28 public void testUpdate() {
29 List<MatchBuilder> matches = new ArrayList<>();
30 Map<String, ParameterValue> params = new HashMap<>();
32 new MatchBuilder().setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
34 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
36 List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
38 assertEquals(1, updated.size());
39 MatchBuilder first = updated.get(0);
40 assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
41 assertSame(ClassifierTestUtils.TCP, first.getIpMatch().getIpProtocol().longValue());
45 public void testUpdate_overrideBySameValue() {
46 List<MatchBuilder> matches = new ArrayList<>();
47 Map<String, ParameterValue> params = new HashMap<>();
48 matches.add(new MatchBuilder()
49 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
50 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
52 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
54 List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
56 assertEquals(1, updated.size());
57 MatchBuilder first = updated.get(0);
58 assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
59 assertSame(ClassifierTestUtils.UDP, first.getIpMatch().getIpProtocol().longValue());
63 public void testUpdate_overrideByDifferentValue() {
64 List<MatchBuilder> matches = new ArrayList<>();
65 Map<String, ParameterValue> params = new HashMap<>();
66 matches.add(new MatchBuilder()
67 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
68 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
70 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
72 thrown.expect(IllegalArgumentException.class);
73 thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
74 Classifier.ETHER_TYPE_CL.update(matches, params);
78 public void testCheckPresenceOfRequiredParameters_EtherTypeMissing() {
79 Map<String, ParameterValue> params = new HashMap<>();
80 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
81 ClassifierTestUtils.TCP));
83 thrown.expect(IllegalArgumentException.class);
84 thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
85 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
89 public void testCheckPresenceOfRequiredParameters_EtherTypeNull() {
90 Map<String, ParameterValue> params = new HashMap<>();
92 ImmutableMap.of(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().build()));
94 thrown.expect(IllegalArgumentException.class);
95 thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
96 Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);