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 IpProtoClassifierTest {
25 public ExpectedException thrown = ExpectedException.none();
28 public void testUpdate() {
29 List<MatchBuilder> matches = new ArrayList<>();
30 Map<String, ParameterValue> params = new HashMap<>();
31 matches.add(new MatchBuilder()
32 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
33 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
34 ClassifierTestUtils.TCP));
36 List<MatchBuilder> updated = Classifier.IP_PROTO_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())));
51 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
52 ClassifierTestUtils.UDP));
54 List<MatchBuilder> updated = Classifier.IP_PROTO_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())));
69 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
70 ClassifierTestUtils.TCP));
72 thrown.expect(IllegalArgumentException.class);
73 thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
74 Classifier.IP_PROTO_CL.update(matches, params);
78 public void testCheckPresenceOfRequiredParameters_ProtoMissing() {
79 Map<String, ParameterValue> params = new HashMap<>();
81 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
83 thrown.expect(IllegalArgumentException.class);
84 thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
85 Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
89 public void testCheckPresenceOfRequiredParameters_ProtoNull() {
90 Map<String, ParameterValue> params = new HashMap<>();
91 params.putAll(ImmutableMap.of(IpProtoClassifierDefinition.PROTO_PARAM, new ParameterValueBuilder().build()));
93 thrown.expect(IllegalArgumentException.class);
94 thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
95 Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);