2 * Copyright (c) 2015 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
8 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertSame;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
18 import com.google.common.collect.ImmutableMap;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.ExpectedException;
22 import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
23 import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
24 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
29 public class IpProtoClassifierTest {
32 public ExpectedException thrown = ExpectedException.none();
35 public void testUpdate() {
36 List<MatchBuilder> matches = new ArrayList<>();
37 Map<String, ParameterValue> params = new HashMap<>();
38 matches.add(new MatchBuilder()
39 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
40 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
41 ClassifierTestUtils.TCP));
43 List<MatchBuilder> updated = Classifier.IP_PROTO_CL.update(matches, params);
45 assertEquals(1, updated.size());
46 MatchBuilder first = updated.get(0);
47 assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
48 assertSame(ClassifierTestUtils.TCP, first.getIpMatch().getIpProtocol().longValue());
52 public void testUpdate_overrideBySameValue() {
53 List<MatchBuilder> matches = new ArrayList<>();
54 Map<String, ParameterValue> params = new HashMap<>();
55 matches.add(new MatchBuilder()
56 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
57 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
58 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
59 ClassifierTestUtils.UDP));
61 List<MatchBuilder> updated = Classifier.IP_PROTO_CL.update(matches, params);
63 assertEquals(1, updated.size());
64 MatchBuilder first = updated.get(0);
65 assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
66 assertSame(ClassifierTestUtils.UDP, first.getIpMatch().getIpProtocol().longValue());
70 public void testUpdate_overrideByDifferentValue() {
71 List<MatchBuilder> matches = new ArrayList<>();
72 Map<String, ParameterValue> params = new HashMap<>();
73 matches.add(new MatchBuilder()
74 .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
75 .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
76 params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
77 ClassifierTestUtils.TCP));
79 thrown.expect(IllegalArgumentException.class);
80 thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
81 Classifier.IP_PROTO_CL.update(matches, params);
85 public void testCheckPresenceOfRequiredParameters_ProtoMissing() {
86 Map<String, ParameterValue> params = new HashMap<>();
88 ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
90 thrown.expect(IllegalArgumentException.class);
91 thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
92 Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
96 public void testCheckPresenceOfRequiredParameters_ProtoNull() {
97 Map<String, ParameterValue> params = new HashMap<>();
98 params.putAll(ImmutableMap.of(IpProtoClassifierDefinition.PROTO_PARAM, new ParameterValueBuilder().build()));
100 thrown.expect(IllegalArgumentException.class);
101 thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
102 Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);