*/
public abstract class Classifier {
+ // Messages for exceptions (also for exception tests)
+ public static final String MSG_CLASSIFICATION_CONFLICT_DETECTED = "Classification conflict detected";
+ public static final String MSG_NOT_SPECIFIED = "not specified";
+ public static final String MSG_PARAMETER_IS_NOT_PRESENT = "parameter is not present";
+ public static final String MSG_MUTUALLY_EXCLUSIVE = "mutually exclusive";
+ public static final String MSG_RANGE_VALUE_MISMATCH = "Range value mismatch.";
+ public static final String MSG_NOT_SUPPORTED = "not supported";
+ public static final String MSG_IS_MISSING = "is missing";
+ public static final String MSG_NOT_PRESENT = "not present";
+
protected final Classifier parent;
public static final EtherTypeClassifier ETHER_TYPE_CL = new EtherTypeClassifier(null);
/**
* The result represents supported parameters for the classifier by renderer
- *
+ *
* @return list of supported parameters by the classifier
*/
public abstract List<SupportedParameterValues> getSupportedParameterValues();
*/
public final ClassificationResult updateMatch(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
if (params == null) {
- return new ClassificationResult("Classifier-instance with classifier-definition-id: " + this.getId()
- + ". No parameters present.");
+ return new ClassificationResult(
+ "Classifier-instance with classifier-definition-id: " + this.getId() + ". No parameters present.");
}
List<MatchBuilder> matchBuilders = matches;
try {
}
/**
- * Checks presence of required {@code params} in order to decide if classifier can update {@code matches} properly
- * in method {@link #update(List, Map)}
- * @param params inserted parameters, not null
- * @throws IllegalArgumentException when any of required {@code params} is not present, see {@link #updateMatch(List, Map)}
+ * Checks presence of required {@code params} in order to decide if classifier can update
+ * {@code matches} properly
+ * in method {@link #update(List, Map)}
+ *
+ * @param params inserted parameters, not null
+ * @throws IllegalArgumentException when any of required {@code params} is not present, see
+ * {@link #updateMatch(List, Map)}
*/
protected abstract void checkPresenceOfRequiredParams(Map<String, ParameterValue> params);
public List<SupportedParameterValues> getSupportedParameterValues() {
List<SupportedIntValue> values = ImmutableList.of(
- new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.ARP_VALUE)
- .build(),
- new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.IPv4_VALUE)
- .build(),
- new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.IPv6_VALUE)
- .build());
+ new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.ARP_VALUE).build(),
+ new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.IPv4_VALUE).build(),
+ new SupportedIntValueBuilder().setValue(EtherTypeClassifierDefinition.IPv6_VALUE).build());
SupportedParameterValuesBuilder b = new SupportedParameterValuesBuilder();
b.setParameterName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM));
b.setParameterType(new IntBuilder().setSupportedIntValue(values).build());
protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM) == null) {
throw new IllegalArgumentException(
- "Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " not specified.");
+ "Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " " + MSG_NOT_SPECIFIED);
}
if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM).getIntValue() == null) {
throw new IllegalArgumentException(
- "Value of " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " parameter is not present.");
+ "Value of " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " " + MSG_PARAMETER_IS_NOT_PRESENT);
}
}
@Override
- protected List<MatchBuilder> update(List<MatchBuilder> matches,
- Map<String, ParameterValue> params) {
+ protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
Long type = params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM).getIntValue();
for (MatchBuilder match : matches) {
EthernetMatchBuilder em;
private void equalOrNotSetValidation(EthernetType ethTypeInMatch, long paramValue) {
if (ethTypeInMatch != null) {
- if (paramValue != ethTypeInMatch.getType().getValue().longValue()) {
- throw new IllegalArgumentException(
- "Classification conflict detected at " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " parameter for values " + ethTypeInMatch
- .getType()
- .getValue() + " and " + paramValue + ". It is not allowed " + "to assign different values to the same parameter among all the classifiers within one rule.");
+ if (paramValue != ethTypeInMatch.getType().getValue()) {
+ throw new IllegalArgumentException(MSG_CLASSIFICATION_CONFLICT_DETECTED + " at "
+ + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " parameter for values "
+ + ethTypeInMatch.getType().getValue() + " and " + paramValue + ". It is not allowed "
+ + "to assign different values to the same parameter among all the classifiers within one rule.");
}
}
}
public List<SupportedParameterValues> getSupportedParameterValues() {
List<SupportedIntValue> values = ImmutableList.of(
- new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.ICMP_VALUE)
- .build(),
- new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.SCTP_VALUE)
- .build(),
- new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.TCP_VALUE)
- .build(),
- new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.UDP_VALUE)
- .build());
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.ICMP_VALUE).build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.SCTP_VALUE).build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.TCP_VALUE).build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.UDP_VALUE).build());
SupportedParameterValuesBuilder b = new SupportedParameterValuesBuilder();
b.setParameterName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM));
b.setParameterType(new IntBuilder().setSupportedIntValue(values).build());
@Override
protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) {
- throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM
- + " not specified.");
+ throw new IllegalArgumentException(
+ "Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " " + MSG_NOT_SPECIFIED);
}
if (params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue() == null) {
- throw new IllegalArgumentException("Value of " + IpProtoClassifierDefinition.PROTO_PARAM
- + " parameter is not present.");
+ throw new IllegalArgumentException(
+ "Value of " + IpProtoClassifierDefinition.PROTO_PARAM + " " + MSG_PARAMETER_IS_NOT_PRESENT);
}
}
private void equalOrNotSetValidation(Short protoInMatch, long paramValue) {
if (protoInMatch != null) {
if (paramValue != protoInMatch.longValue()) {
- throw new IllegalArgumentException("Classification conflict detected at " + IpProtoClassifierDefinition.PROTO_PARAM
- + " parameter for values " + protoInMatch.shortValue() + " and " + paramValue
- + ". It is not allowed "
+ throw new IllegalArgumentException(MSG_CLASSIFICATION_CONFLICT_DETECTED + " at "
+ + IpProtoClassifierDefinition.PROTO_PARAM + " parameter for values " + protoInMatch + " and "
+ + paramValue + ". It is not allowed "
+ "to assign different values to the same parameter among all the classifiers within one rule.");
}
}
try {
readEthType = match.getEthernetMatch().getEthernetType().getType().getValue();
} catch (NullPointerException e) {
- throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
- + " is missing.");
+ throw new IllegalArgumentException(
+ "Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " " + MSG_IS_MISSING);
}
if (!FlowUtils.IPv4.equals(readEthType) && !FlowUtils.IPv6.equals(readEthType)) {
throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
/**
* Return the IpProtocol value. May return null.
+ *
* @param params the parameters of classifier-instance inserted by user
* @return the IpProtocol value
*/
if (params.get(portParam) != null) {
StringBuilder paramLog = new StringBuilder();
if (params.get(portParam).getIntValue() == null) {
- paramLog.append("Value of ")
- .append(portParam)
- .append(" parameter is not specified.");
+ paramLog.append("Value of ").append(portParam).append(" parameter " + MSG_NOT_SPECIFIED);
throw new IllegalArgumentException(paramLog.toString());
}
- if(params.get(portRangeParam) != null) {
+ if (params.get(portRangeParam) != null) {
paramLog.append("Source port parameters ")
.append(portParam)
.append(" and ")
.append(portRangeParam)
- .append(" are mutually exclusive.");
+ .append(" are " + MSG_MUTUALLY_EXCLUSIVE);
throw new IllegalArgumentException(paramLog.toString());
}
}
private void validateRangeValue(RangeValue rangeValueParam) {
if (rangeValueParam == null) {
- throw new IllegalArgumentException("Range parameter is specifiet but value is not present.");
+ throw new IllegalArgumentException(
+ "Range parameter is specified but value is " + Classifier.MSG_NOT_PRESENT);
}
final Long min = rangeValueParam.getMin();
final Long max = rangeValueParam.getMax();
if (min > max) {
- throw new IllegalArgumentException("Range value mismatch. " + min + " is greater than MAX " + max + ".");
+ throw new IllegalArgumentException(
+ MSG_RANGE_VALUE_MISMATCH + " MIN " + min + " is greater than MAX " + max + ".");
}
}
public List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
Set<Long> sPorts = new HashSet<>();
Set<Long> dPorts = new HashSet<>();
- addToPortSet(params, L4ClassifierDefinition.SRC_PORT_PARAM, L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, sPorts);
- addToPortSet(params, L4ClassifierDefinition.DST_PORT_PARAM, L4ClassifierDefinition.DST_PORT_RANGE_PARAM, dPorts);
+ addToPortSet(params, L4ClassifierDefinition.SRC_PORT_PARAM, L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
+ sPorts);
+ addToPortSet(params, L4ClassifierDefinition.DST_PORT_PARAM, L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
+ dPorts);
List<MatchBuilder> newMatches = new ArrayList<>();
for (MatchBuilder matchBuilder : matches) {
Layer4Match l4Match = matchBuilder.getLayer4Match();
return newMatches;
}
- private void addToPortSet(Map<String, ParameterValue> params, String portParam, String portRangeParam, Set<Long> portSet) {
+ private void addToPortSet(Map<String, ParameterValue> params, String portParam, String portRangeParam,
+ Set<Long> portSet) {
if (params.get(portParam) != null) {
portSet.add(params.get(portParam).getIntValue());
} else if (params.get(portRangeParam) != null) {
return new SctpMatchBuilder().build();
}
throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + ": value " + ipProto
- + " is not supported.");
+ + " is " + Classifier.MSG_NOT_SUPPORTED);
}
private Set<Long> createSetFromRange(RangeValue rangeValueParam) {
if (!sPorts.isEmpty() && dPorts.isEmpty()) {
for (Long srcPort : sPorts) {
equalOrNotSetValidation(udpMatch.getUdpSourcePort(), srcPort.longValue());
- udpMatches.add(new UdpMatchBuilder(udpMatch).setUdpSourcePort(new PortNumber(srcPort.intValue())).build());
+ udpMatches
+ .add(new UdpMatchBuilder(udpMatch).setUdpSourcePort(new PortNumber(srcPort.intValue())).build());
}
} else if (sPorts.isEmpty() && !dPorts.isEmpty()) {
for (Long dstPort : dPorts) {
if (!sPorts.isEmpty() && dPorts.isEmpty()) {
for (Long srcPort : sPorts) {
equalOrNotSetValidation(tcpMatch.getTcpSourcePort(), srcPort.longValue());
- tcpMatches.add(new TcpMatchBuilder(tcpMatch).setTcpSourcePort(new PortNumber(srcPort.intValue())).build());
+ tcpMatches
+ .add(new TcpMatchBuilder(tcpMatch).setTcpSourcePort(new PortNumber(srcPort.intValue())).build());
}
} else if (sPorts.isEmpty() && !dPorts.isEmpty()) {
for (Long dstPort : dPorts) {
if (!sPorts.isEmpty() && dPorts.isEmpty()) {
for (Long srcPort : sPorts) {
equalOrNotSetValidation(sctpMatch.getSctpSourcePort(), srcPort.longValue());
- sctpMatches.add(new SctpMatchBuilder(sctpMatch).setSctpSourcePort(new PortNumber(srcPort.intValue()))
- .build());
+ sctpMatches
+ .add(new SctpMatchBuilder(sctpMatch).setSctpSourcePort(new PortNumber(srcPort.intValue())).build());
}
} else if (sPorts.isEmpty() && !dPorts.isEmpty()) {
for (Long dstPort : dPorts) {
equalOrNotSetValidation(sctpMatch.getSctpDestinationPort(), dstPort.longValue());
- sctpMatches.add(new SctpMatchBuilder(sctpMatch).setSctpDestinationPort(new PortNumber(dstPort.intValue()))
- .build());
+ sctpMatches.add(new SctpMatchBuilder(sctpMatch)
+ .setSctpDestinationPort(new PortNumber(dstPort.intValue())).build());
}
} else if (!sPorts.isEmpty() && !dPorts.isEmpty()) {
for (Long srcPort : sPorts) {
for (Long dstPort : dPorts) {
equalOrNotSetValidation(sctpMatch.getSctpSourcePort(), srcPort.longValue());
equalOrNotSetValidation(sctpMatch.getSctpDestinationPort(), dstPort.longValue());
- sctpMatches.add(new SctpMatchBuilder(sctpMatch).setSctpSourcePort(new PortNumber(srcPort.intValue()))
- .setSctpDestinationPort(new PortNumber(dstPort.intValue()))
- .build());
+ sctpMatches
+ .add(new SctpMatchBuilder(sctpMatch).setSctpSourcePort(new PortNumber(srcPort.intValue()))
+ .setSctpDestinationPort(new PortNumber(dstPort.intValue()))
+ .build());
}
}
}
private void equalOrNotSetValidation(PortNumber portInMatch, long paramValue) {
if (portInMatch != null) {
if (paramValue != portInMatch.getValue().longValue()) {
- throw new IllegalArgumentException("Classification conflict detected for port values "
+ throw new IllegalArgumentException(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED + " for port values "
+ portInMatch.getValue().longValue() + " and " + paramValue + ". It is not allowed "
+ "to assign different values to the same parameter among all the classifiers within one rule.");
}
try {
proto = Long.valueOf(match.getIpMatch().getIpProtocol().longValue());
} catch (NullPointerException e) {
- throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " is missing.");
+ throw new IllegalArgumentException(
+ "Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " " + MSG_IS_MISSING);
}
- if (!IpProtoClassifierDefinition.TCP_VALUE.equals(proto) && !IpProtoClassifierDefinition.UDP_VALUE.equals(proto)
+ if (!IpProtoClassifierDefinition.TCP_VALUE.equals(proto)
+ && !IpProtoClassifierDefinition.UDP_VALUE.equals(proto)
&& !IpProtoClassifierDefinition.SCTP_VALUE.equals(proto)) {
throw new IllegalArgumentException("Value of parameter " + IpProtoClassifierDefinition.PROTO_PARAM
- + " is not supported.");
+ + " is " + Classifier.MSG_NOT_SUPPORTED);
}
}
}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.policyenforcer.NetworkElements;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.RspName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfcName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePathBuilder;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-
@RunWith(PowerMockRunner.class)
@PrepareForTest(ChainAction.class)
public class ChainActionTest {
private Endpoint endpoint;
private EndpointManager endpointManager;
private EgKey egKey;
- private TenantId tenant = new TenantId("e09a2308-6ffa-40af-92a2-69f54b2cf3e4");
+ private TenantId tenantId = new TenantId("e09a2308-6ffa-40af-92a2-69f54b2cf3e4");
@SuppressWarnings("unchecked")
@Before
- public void initialise() throws Exception {
+ public void init() throws Exception {
chainAction = new ChainAction();
- sfcPath = mock(ServiceFunctionPath.class);
- when(sfcPath.getName()).thenReturn(new SfpName("sfcPathName"));
- when(sfcPath.isSymmetric()).thenReturn(true);
+ sfcPath = new ServiceFunctionPathBuilder().setName(new SfpName("sfcPathName")).setSymmetric(true).build();
+ rsp = new RenderedServicePathBuilder().setName(new RspName("rspName")).build();
+ endpoint = new EndpointBuilder().setL2Context(new L2BridgeDomainId("L2context"))
+ .setMacAddress(new MacAddress("01:23:45:67:89:ab"))
+ .setTenant(tenantId)
+ .build();
ctx = mock(OfContext.class);
dataBroker = mock(DataBroker.class);
when(rTx.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
optRsp = mock(Optional.class);
when(checkedFuture.checkedGet()).thenReturn(optRsp);
- rsp = mock(RenderedServicePath.class);
when(optRsp.isPresent()).thenReturn(true).thenReturn(false);
when(optRsp.get()).thenReturn(rsp);
endpointFwdCtxOrdinals = mock(EndpointFwdCtxOrdinals.class);
when(netElements.getSrcEpOrdinals()).thenReturn(endpointFwdCtxOrdinals);
when(netElements.getDstEpOrdinals()).thenReturn(endpointFwdCtxOrdinals);
- endpoint = mock(Endpoint.class);
when(netElements.getSrcEp()).thenReturn(endpoint);
- when(netElements.getSrcEp().getTenant()).thenReturn(tenant);
endpointManager = mock(EndpointManager.class);
when(ctx.getEndpointManager()).thenReturn(endpointManager);
egKey = mock(EgKey.class);
- Set<EgKey> keysForEndpoint = new HashSet<EgKey>();
+ Set<EgKey> keysForEndpoint = new HashSet<>();
keysForEndpoint.add(egKey);
when(endpointManager.getEgKeysForEndpoint(any(Endpoint.class))).thenReturn(keysForEndpoint);
}
@Test
- public void staticTest() {
- Assert.assertNotNull(chainAction.getId());
- Assert.assertNotNull(chainAction.getActionDef());
+ public void testGetters() {
+ assertEquals(ChainActionDefinition.ID, chainAction.getId());
+ assertEquals(ChainActionDefinition.DEFINITION, chainAction.getActionDef());
}
@Test
- public void updateActionTestDirectionOutOpendaylightSfcNull() {
+ public void testUpdateAction_DirectionOut_OpendaylightSfcNull() {
ActionBuilder actionBuilder = mock(ActionBuilder.class);
- List<ActionBuilder> actions = Arrays.asList(actionBuilder);
- Map<String, Object> params = new HashMap<String, Object>();
+ List<ActionBuilder> actions = Collections.singletonList(actionBuilder);
+ Map<String, Object> params = new HashMap<>();
String chainName = "chainName";
params.put(ChainActionDefinition.SFC_CHAIN_NAME, chainName);
- Integer order = Integer.valueOf(0);
+ Integer order = 0;
OfWriter ofWriter = mock(OfWriter.class);
PowerMockito.mockStatic(ChainAction.class);
- when(ChainAction.getSfcPath(new SfcName(chainName))).thenReturn(sfcPath);
+ SfcName sfcName = new SfcName(chainName);
+ when(ChainAction.getSfcPath(eq(sfcName))).thenReturn(sfcPath);
chainAction.setResolvedSymmetricChains(Collections.singletonList(chainName));
List<ActionBuilder> result =
}
@Test
- public void updateActionTestParamsNull() {
+ public void testUpdateAction_ParamsNull() {
ActionBuilder actionBuilder = mock(ActionBuilder.class);
- List<ActionBuilder> actions = Arrays.asList(actionBuilder);
- Integer order = Integer.valueOf(0);
+ List<ActionBuilder> actions = Collections.singletonList(actionBuilder);
+ Integer order = 0;
OfWriter ofWriter = mock(OfWriter.class);
List<ActionBuilder> result =
}
@Test
- public void updateActionTestChainNameNull() {
+ public void testUpdateAction_ChainNameNull() {
ActionBuilder actionBuilder = mock(ActionBuilder.class);
- List<ActionBuilder> actions = Arrays.asList(actionBuilder);
- Map<String, Object> params = new HashMap<String, Object>();
+ List<ActionBuilder> actions = Collections.singletonList(actionBuilder);
+ Map<String, Object> params = new HashMap<>();
params.put(ChainActionDefinition.SFC_CHAIN_NAME, null);
- Integer order = Integer.valueOf(0);
+ Integer order = 0;
NetworkElements netElements = mock(NetworkElements.class);
OfWriter ofWriter = mock(OfWriter.class);
}
@Test
- public void updateActionTest() {
+ public void testUpdateAction() {
ActionBuilder actionBuilder = mock(ActionBuilder.class);
- List<ActionBuilder> actions = Arrays.asList(actionBuilder);
- Map<String, Object> params = new HashMap<String, Object>();
+ List<ActionBuilder> actions = Collections.singletonList(actionBuilder);
+ Map<String, Object> params = new HashMap<>();
String chainName = "chainName";
params.put(ChainActionDefinition.SFC_CHAIN_NAME, chainName);
- Integer order = Integer.valueOf(0);
+ Integer order = 0;
OfWriter ofWriter = mock(OfWriter.class);
+ ServiceFunctionPath sfcPathNameNull = new ServiceFunctionPathBuilder().setName(null).setSymmetric(true).build();
+
PowerMockito.mockStatic(ChainAction.class);
- when(ChainAction.getSfcPath(new SfcName(chainName))).thenReturn(sfcPath);
- when(sfcPath.getName()).thenReturn(null);
+ when(ChainAction.getSfcPath(new SfcName(chainName))).thenReturn(sfcPathNameNull);
List<ActionBuilder> result =
chainAction.updateAction(actions, params, order, netElements, ofWriter, ctx, Direction.Out);
}
@Test
- public void isValidTestParameterValueNull() {
- ActionInstance actionInstance = mock(ActionInstance.class);
- Assert.assertFalse(chainAction.validate(actionInstance).isValid());
+ public void testIsValid_ParameterValueNull() {
+ ActionInstance actionInstance = mock(ActionInstance.class);
+ Assert.assertFalse(chainAction.validate(actionInstance).isValid());
}
}
/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
public class ClassificationResultTest {
- private ClassificationResult result;
-
- private MatchBuilder matchBuilder;
private List<MatchBuilder> matches;
private String errorMessage = "errorMessage";
@Before
- public void initialise() {
- matchBuilder = mock(MatchBuilder.class);
- matches = Arrays.asList(matchBuilder);
+ public void init() {
+ MatchBuilder matchBuilder = mock(MatchBuilder.class);
+ matches = Collections.singletonList(matchBuilder);
}
@Test
- public void getMatchBuildersTestSuccess() {
- result = new ClassificationResult(matches);
- Assert.assertEquals(matches, result.getMatchBuilders());
+ public void testGetMatchBuilders_Success() {
+ ClassificationResult result = new ClassificationResult(matches);
+ assertEquals(matches, result.getMatchBuilders());
}
@Test(expected = IllegalStateException.class)
- public void getMatchBuildersTestFailure() {
- result = new ClassificationResult(errorMessage);
+ public void testGetMatchBuilders_Failure() {
+ ClassificationResult result = new ClassificationResult(errorMessage);
result.getMatchBuilders();
}
@Test
- public void getErrorMessageTest() {
- result = new ClassificationResult(errorMessage);
- Assert.assertEquals(errorMessage, result.getErrorMessage());
- result = new ClassificationResult(matches);
- Assert.assertTrue(result.getErrorMessage().isEmpty());
+ public void testGetErrorMessage() {
+ ClassificationResult result1 = new ClassificationResult(errorMessage);
+ assertEquals(errorMessage, result1.getErrorMessage());
+
+ ClassificationResult result2 = new ClassificationResult(matches);
+ assertTrue(result2.getErrorMessage().isEmpty());
}
@Test
- public void isSuccessfullTest() {
- result = new ClassificationResult(errorMessage);
- Assert.assertFalse(result.isSuccessfull());
- result = new ClassificationResult(matches);
- Assert.assertTrue(result.isSuccessfull());
+ public void testIsSuccessfull() {
+ ClassificationResult result1 = new ClassificationResult(errorMessage);
+ assertFalse(result1.isSuccessfull());
+
+ ClassificationResult result2 = new ClassificationResult(matches);
+ assertTrue(result2.isSuccessfull());
}
}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collections;
Map<String, ParameterValue> params;
@Before
- public void setUp() {
+ public void init() {
matches = new ArrayList<>(Collections.singletonList(new MatchBuilder()));
params = new HashMap<>();
}
@Test
- public void updateMatchTest() {
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- FlowUtils.IPv4));
+ public void testUpdateMatch() {
+ Long dstRangeStart = 8079L;
+ Long dstRangeEnd = 8081L;
+ Long singlePort = 80L;
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
- params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, 80));
+ params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, singlePort));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
ClassificationResult result = Classifier.L4_CL.updateMatch(matches, params);
+
assertEquals(true, result.isSuccessfull());
assertEquals(3, result.getMatchBuilders().size());
Set<Long> dstPorts = new HashSet<>();
for (MatchBuilder match : result.getMatchBuilders()) {
- assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
- assertEquals(true, new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort()
- .getValue()
- .intValue() == 80);
- dstPorts.add(Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, match.getEthernetMatch().getEthernetType());
+ assertSame(singlePort.intValue(),
+ new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort().getValue());
+ dstPorts.add(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
.getValue()
- .longValue()));
+ .longValue());
}
- for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
- assertEquals(true, dstPorts.contains((i)));
+ for (Long dstPort = dstRangeStart; dstPort <= dstRangeEnd; dstPort++) {
+ assertTrue(dstPorts.contains(dstPort));
}
}
}
import java.util.Map;
+import com.google.common.collect.ImmutableMap;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
-import com.google.common.collect.ImmutableMap;
-
public class ClassifierTestUtils {
static final EthernetType IPV4_ETH_TYPE = new EthernetTypeBuilder().setType(new EtherType(FlowUtils.IPv4)).build();
static final EthernetType IPV6_ETH_TYPE = new EthernetTypeBuilder().setType(new EtherType(FlowUtils.IPv6)).build();
- static final Long TCP = Long.valueOf(6);
- static final Long UDP = Long.valueOf(17);
- static final Long SCTP = Long.valueOf(132);
+ static final Long TCP = 6L;
+ static final Long UDP = 17L;
+ static final Long SCTP = 132L;
static Map<String, ParameterValue> createRangeValueParam(String paramName, long min, long max) {
- return ImmutableMap.<String, ParameterValue> of(paramName,
- new ParameterValueBuilder()
- .setRangeValue(new RangeValueBuilder()
- .setMin(min)
- .setMax(max)
- .build())
- .build());
+ return ImmutableMap.of(paramName, new ParameterValueBuilder()
+ .setRangeValue(new RangeValueBuilder().setMin(min).setMax(max).build()).build());
}
static Map<String, ParameterValue> createIntValueParam(String paramName, long value) {
- return ImmutableMap.<String, ParameterValue> of(paramName,
- new ParameterValueBuilder()
- .setIntValue(value)
- .build());
+ return ImmutableMap.of(paramName, new ParameterValueBuilder().setIntValue(value).build());
}
- static final EthernetMatch createEthernetMatch(EthernetType ethType) {
- return new EthernetMatchBuilder()
- .setEthernetType(ethType)
- .build();
+ static EthernetMatch createEthernetMatch(EthernetType ethType) {
+ return new EthernetMatchBuilder().setEthernetType(ethType).build();
}
- static final IpMatch createIpMatch(short ipProtoValue) {
- return new IpMatchBuilder()
- .setIpProtocol(ipProtoValue)
- .build();
+ static IpMatch createIpMatch(short ipProtoValue) {
+ return new IpMatchBuilder().setIpProtocol(ipProtoValue).build();
}
- static final Layer4Match createUdpDstPort(int portNumber) {
- return new UdpMatchBuilder()
- .setUdpDestinationPort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createUdpDstPort(int portNumber) {
+ return new UdpMatchBuilder().setUdpDestinationPort(new PortNumber(portNumber)).build();
}
- static final Layer4Match createUdpSrcPort(int portNumber) {
- return new UdpMatchBuilder()
- .setUdpSourcePort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createUdpSrcPort(int portNumber) {
+ return new UdpMatchBuilder().setUdpSourcePort(new PortNumber(portNumber)).build();
}
- final Layer4Match createTcpDstPort(int portNumber) {
- return new TcpMatchBuilder()
- .setTcpDestinationPort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createTcpDstPort(int portNumber) {
+ return new TcpMatchBuilder().setTcpDestinationPort(new PortNumber(portNumber)).build();
}
- final Layer4Match createTcpSrcPort(int portNumber) {
- return new TcpMatchBuilder()
- .setTcpSourcePort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createTcpSrcPort(int portNumber) {
+ return new TcpMatchBuilder().setTcpSourcePort(new PortNumber(portNumber)).build();
}
- final static Layer4Match createSctpDstPort(int portNumber) {
- return new SctpMatchBuilder()
- .setSctpDestinationPort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createSctpDstPort(int portNumber) {
+ return new SctpMatchBuilder().setSctpDestinationPort(new PortNumber(portNumber)).build();
}
- final static Layer4Match createSctpSrcPort(int portNumber) {
- return new SctpMatchBuilder()
- .setSctpSourcePort(new PortNumber(portNumber))
- .build();
+ static Layer4Match createSctpSrcPort(int portNumber) {
+ return new SctpMatchBuilder().setSctpSourcePort(new PortNumber(portNumber)).build();
}
-}
\ No newline at end of file
+}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
+import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
-import com.google.common.collect.ImmutableMap;
-
public class EtherTypeClassifierTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- List<MatchBuilder> matches;
- Map<String, ParameterValue> params;
+ @Test
+ public void testUpdate() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(
+ new MatchBuilder().setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
- @Before
- public void setUp() {
- matches = new ArrayList<>();
- params = new HashMap<>();
- }
+ List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
- @Test
- public void setValueTest() {
- matches.add(new MatchBuilder().setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- FlowUtils.IPv4));
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.TCP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.TCP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByTheSameValueTest() {
- matches.add(new MatchBuilder().setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)).setIpMatch(
- ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- FlowUtils.IPv6));
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.UDP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+ public void testUpdate_overrideBySameValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
+
+ List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.UDP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByDifferentValueTest() {
- matches.add(new MatchBuilder().setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)).setIpMatch(
- ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- FlowUtils.IPv6));
+ public void testUpdate_overrideByDifferentValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Classification conflict detected");
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
+ Classifier.ETHER_TYPE_CL.update(matches, params);
}
@Test
- public void checkPresenceOfRequiredParameters1Test() {
+ public void testCheckPresenceOfRequiredParameters_EtherTypeMissing() {
+ Map<String, ParameterValue> params = new HashMap<>();
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not specified.");
+ thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters2Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- new ParameterValueBuilder().build()));
+ public void testCheckPresenceOfRequiredParameters_EtherTypeNull() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(
+ ImmutableMap.of(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Value of ethertype parameter is not present");
+ thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
}
}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
+import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
-import com.google.common.collect.ImmutableMap;
-
public class IpProtoClassifierTest {
- List<MatchBuilder> matches;
- Map<String, ParameterValue> params;
-
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Before
- public void setUp() {
- matches = new ArrayList<>();
- params = new HashMap<>();
- }
-
@Test
- public void setValueTest() {
- matches.add(new MatchBuilder().setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ public void testUpdate() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
- matches = Classifier.IP_PROTO_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.TCP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+
+ List<MatchBuilder> updated = Classifier.IP_PROTO_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.TCP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByTheSameValueTest() {
- matches.add(new MatchBuilder().setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)).setIpMatch(
- ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
+ public void testUpdate_overrideBySameValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
- matches = Classifier.IP_PROTO_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.UDP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+
+ List<MatchBuilder> updated = Classifier.IP_PROTO_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.UDP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByDifferentValueTest() {
- matches.add(new MatchBuilder().setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)).setIpMatch(
- ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
+ public void testUpdate_overrideByDifferentValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Classification conflict detected");
- matches = Classifier.IP_PROTO_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
+ Classifier.IP_PROTO_CL.update(matches, params);
}
@Test
- public void checkPresenceOfRequiredParameters1Test() {
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
- FlowUtils.IPv4));
+ public void testCheckPresenceOfRequiredParameters_ProtoMissing() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not specified");
+ thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters2Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(IpProtoClassifierDefinition.PROTO_PARAM,
- new ParameterValueBuilder().build()));
+ public void testCheckPresenceOfRequiredParameters_ProtoNull() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ImmutableMap.of(IpProtoClassifierDefinition.PROTO_PARAM, new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Value of proto parameter is not present");
+ thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
}
}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
-import com.google.common.collect.ImmutableMap;
-
public class L4ClassifierTest {
- List<MatchBuilder> matches;
-
- Map<String, ParameterValue> params;
+ private static final long LESSER_RANGE_START = 79L;
+ private static final long LESSER_RANGE_END = 81L;
+ private static final long GREATER_RANGE_START = 8079L;
+ private static final long GREATER_RANGE_END = 8081L;
+ private static final long SINGLE_PORT = 80L;
+ private static final int SINGLE_PORT_INT = 80;
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Before
- public void setUp() {
- params = new HashMap<>();
- matches = new ArrayList<>();
- }
-
@Test
- public void setTcpSrcPortTest() {
- matches.add(new MatchBuilder().setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
- Long sPort = Long.valueOf(80);
+ public void testUpdate_TcpSrcPort() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ Long sPort = SINGLE_PORT;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, sPort));
- matches = Classifier.L4_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- TcpMatch match = new TcpMatchBuilder((TcpMatch) matches.get(0).getLayer4Match()).build();
- assertEquals(true, sPort.equals(match.getTcpSourcePort().getValue().longValue()));
- assertEquals(true, match.getTcpDestinationPort() == null);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ TcpMatch match = new TcpMatchBuilder((TcpMatch) first.getLayer4Match()).build();
+ assertSame(sPort, match.getTcpSourcePort().getValue().longValue());
+ assertNull(match.getTcpDestinationPort());
}
@Test
- public void setTcpDstPortTest() {
- Long dPort = Long.valueOf(80);
- matches.add(new MatchBuilder().setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
+ public void testUpdate_TcpDstPort() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long dPort = SINGLE_PORT;
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.DST_PORT_PARAM, dPort));
- matches = Classifier.L4_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- TcpMatch match = new TcpMatchBuilder((TcpMatch) matches.get(0).getLayer4Match()).build();
- assertEquals(true, dPort.equals(match.getTcpDestinationPort().getValue().longValue()));
- assertEquals(true, match.getTcpSourcePort() == null);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ TcpMatch match = new TcpMatchBuilder((TcpMatch) first.getLayer4Match()).build();
+ assertSame(dPort, match.getTcpDestinationPort().getValue().longValue());
+ assertNull(match.getTcpSourcePort());
}
@Test
- public void setTcpSrcPortDstPortRangeTest() {
- matches.add(new MatchBuilder().setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
- Long srcPort = Long.valueOf(80);
+ public void testUpdate_TcpSrcPort_DstPortRange() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
+ Long srcPort = SINGLE_PORT;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, srcPort));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
- matches = Classifier.L4_CL.update(matches, params);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
Set<Long> dstPorts = new HashSet<>();
- for (MatchBuilder match : matches) {
- assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
- assertEquals(true,
- Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort().getValue())
- .equals(srcPort));
+ for (MatchBuilder match : updated) {
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, match.getEthernetMatch().getEthernetType());
+ assertEquals(srcPort,
+ Long.valueOf(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpSourcePort().getValue()));
dstPorts.add(new TcpMatchBuilder((TcpMatch) match.getLayer4Match()).getTcpDestinationPort()
.getValue()
.longValue());
}
- for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
- assertEquals(true, dstPorts.contains((i)));
+ for (Long port = dstRangeStart; port <= dstRangeEnd; port++) {
+ assertTrue(dstPorts.contains((port)));
}
}
@Test
- public void overrideDstPortWithTheSameValueTest() {
- Long dPort = Long.valueOf(80);
- matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(80)).setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
+ public void testUpdate_OverrideDstPortWithTheSameValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long dPort = SINGLE_PORT;
+ matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(SINGLE_PORT_INT))
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.DST_PORT_PARAM, dPort));
- matches = Classifier.L4_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- UdpMatch match = new UdpMatchBuilder((UdpMatch) matches.get(0).getLayer4Match()).build();
- assertEquals(true, dPort.equals(match.getUdpDestinationPort().getValue().longValue()));
- assertEquals(true, match.getUdpSourcePort() == null);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ UdpMatch match = new UdpMatchBuilder((UdpMatch) first.getLayer4Match()).build();
+ assertSame(dPort, match.getUdpDestinationPort().getValue().longValue());
+ assertNull(match.getUdpSourcePort());
}
@Test
- public void addUdpSrcPortRangeTest() {
- matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(80)).setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
- Long srcRangeStart = Long.valueOf(8079);
- Long srcRangeEnd = Long.valueOf(8081);
+ public void testUpdate_AddUdpSrcPortRange() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(SINGLE_PORT_INT))
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ Long srcRangeStart = GREATER_RANGE_START;
+ Long srcRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
srcRangeStart, srcRangeEnd));
- matches = Classifier.L4_CL.update(matches, params);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(3, updated.size());
Set<Long> srcPorts = new HashSet<>();
- for (MatchBuilder match : matches) {
- assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
- assertEquals(true, new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort()
- .getValue()
- .intValue() == 80);
- assertEquals(true, new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort()
- .getValue()
- .longValue() == 80);
- srcPorts.add(new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpSourcePort()
+ for (MatchBuilder match : updated) {
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, match.getEthernetMatch().getEthernetType());
+ assertSame(SINGLE_PORT_INT,
+ new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort().getValue());
+ assertEquals(SINGLE_PORT_INT, new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort()
.getValue()
.longValue());
+ srcPorts
+ .add(new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpSourcePort()
+ .getValue()
+ .longValue());
}
- for (Long i = srcRangeStart; i <= srcRangeEnd; i++) {
- assertEquals(true, srcPorts.contains((i)));
+ for (Long port = srcRangeStart; port <= srcRangeEnd; port++) {
+ assertTrue(srcPorts.contains((port)));
}
}
@Test
- public void setUdpSrcPortRangeDstPortTest() {
- matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(80)).setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
- Long dPort = Long.valueOf(80);
- Long srcRangeStart = Long.valueOf(8079);
- Long srcRangeEnd = Long.valueOf(8081);
+ public void testUpdate_UdpSrcPortRange_DstPort() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createUdpDstPort(SINGLE_PORT_INT))
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE)));
+ Long dPort = SINGLE_PORT;
+ Long srcRangeStart = GREATER_RANGE_START;
+ Long srcRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.DST_PORT_PARAM, dPort));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
srcRangeStart, srcRangeEnd));
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
- matches = Classifier.L4_CL.update(matches, params);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(3, updated.size());
Set<Long> srcPorts = new HashSet<>();
- for (MatchBuilder match : matches) {
- assertEquals(true, ClassifierTestUtils.IPV6_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
- assertEquals(
- true,
- dPort.equals(new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort()
- .getValue()
- .longValue()));
- srcPorts.add(Long.valueOf(new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpSourcePort()
+ for (MatchBuilder match : updated) {
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, match.getEthernetMatch().getEthernetType());
+ assertSame(dPort, new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpDestinationPort()
.getValue()
- .longValue()));
+ .longValue());
+ srcPorts
+ .add(new UdpMatchBuilder((UdpMatch) match.getLayer4Match()).getUdpSourcePort()
+ .getValue()
+ .longValue());
}
- for (Long i = srcRangeStart; i <= srcRangeEnd; i++) {
- assertEquals(true, srcPorts.contains((i)));
+ for (Long port = srcRangeStart; port <= srcRangeEnd; port++) {
+ assertTrue(srcPorts.contains((port)));
}
}
@Test
- public void overrideSrcPortWithTheSameValueTest() {
- Long sPort = Long.valueOf(80);
+ public void testUpdate_OverrideSrcPortWithTheSameValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long sPort = SINGLE_PORT;
matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createSctpSrcPort(sPort.intValue()))
.setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.SCTP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, sPort));
- matches = Classifier.L4_CL.update(matches, params);
- assertEquals(true,
- ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- SctpMatch match = new SctpMatchBuilder((SctpMatch) matches.get(0).getLayer4Match()).build();
- assertEquals(true, sPort.equals(match.getSctpSourcePort().getValue().longValue()));
- assertEquals(true, match.getSctpDestinationPort() == null);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ SctpMatch match = new SctpMatchBuilder((SctpMatch) first.getLayer4Match()).build();
+ assertSame(sPort, match.getSctpSourcePort().getValue().longValue());
+ assertNull(match.getSctpDestinationPort());
}
@Test
- public void addSctpDstPortRangeTest() {
- matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createSctpSrcPort(80)).setEthernetMatch(
- ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
+ public void testUpdate_AddSctpDstPortRange() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createSctpSrcPort(SINGLE_PORT_INT))
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.SCTP));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
- matches = Classifier.L4_CL.update(matches, params);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(3, updated.size());
Set<Long> dstPorts = new HashSet<>();
- for (MatchBuilder match : matches) {
- assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(match.getEthernetMatch().getEthernetType()));
- assertEquals(true, new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpSourcePort()
- .getValue()
- .intValue() == 80);
- dstPorts.add(Long.valueOf(new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpDestinationPort()
+ for (MatchBuilder match : updated) {
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, match.getEthernetMatch().getEthernetType());
+ assertSame(SINGLE_PORT_INT,
+ new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpSourcePort().getValue());
+ dstPorts.add(new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpDestinationPort()
.getValue()
- .longValue()));
+ .longValue());
}
- for (Long i = dstRangeStart; i <= dstRangeEnd; i++) {
- assertEquals(true, dstPorts.contains((i)));
+ for (Long port = dstRangeStart; port <= dstRangeEnd; port++) {
+ assertTrue(dstPorts.contains((port)));
}
}
@Test
- public void setSctpSrcPortRangeDstPortRangeTest() {
- matches.add(new MatchBuilder().setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
- Long srcRangeStart = Long.valueOf(79);
- Long srcRangeEnd = Long.valueOf(81);
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
+ public void testUpdate_Sctp_SrcPortRange_DstPortRange() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder()
+ .setEthernetMatch(
+ ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE)));
+ Long srcRangeStart = LESSER_RANGE_START;
+ Long srcRangeEnd = LESSER_RANGE_END;
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.SCTP));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
- matches = Classifier.L4_CL.update(matches, params);
+
+ List<MatchBuilder> updated = Classifier.L4_CL.update(matches, params);
+
+ assertEquals(9, updated.size());
Set<Pair<Long, Long>> set = new HashSet<>();
- for (MatchBuilder match : matches) {
- Long srcPort = Long.valueOf(new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpSourcePort()
+ for (MatchBuilder match : updated) {
+ Long srcPort =
+ new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpSourcePort().getValue().longValue();
+ Long dstPort = new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpDestinationPort()
.getValue()
- .longValue());
- Long dstPort = Long.valueOf(new SctpMatchBuilder((SctpMatch) match.getLayer4Match()).getSctpDestinationPort()
- .getValue()
- .longValue());
+ .longValue();
set.add(Pair.of(srcPort, dstPort));
}
- for (Long i = srcRangeStart; i <= srcRangeEnd; i++) {
- for (Long j = dstRangeStart; j <= dstRangeEnd; j++) {
- assertEquals(true, set.contains(Pair.of(i, j)));
+ for (Long sPort = srcRangeStart; sPort <= srcRangeEnd; sPort++) {
+ for (Long dPort = dstRangeStart; dPort <= dstRangeEnd; dPort++) {
+ assertTrue(set.contains(Pair.of(sPort, dPort)));
}
}
}
@Test
- public void srcPortSrtPortRangeMutualExclusionTest() {
- matches.add(new MatchBuilder());
- Long srcRangeStart = Long.valueOf(8079);
- Long srcRangeEnd = Long.valueOf(8081);
- Long srcPort = Long.valueOf(80);
+ public void testCheckPresenceOfRequiredParams_SrcPort_SrtPortRange_MutualExclusion() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long srcRangeStart = GREATER_RANGE_START;
+ Long srcRangeEnd = GREATER_RANGE_END;
+ Long srcPort = SINGLE_PORT;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.SCTP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.SRC_PORT_PARAM, srcPort));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
srcRangeStart, srcRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("mutually exclusive");
+ thrown.expectMessage(Classifier.MSG_MUTUALLY_EXCLUSIVE);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void dstPortSrtPortRangeMutualExclusionTest() {
- matches.add(new MatchBuilder());
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
- Long dstPort = Long.valueOf(80);
+ public void testCheckPresenceOfRequiredParams_DstPort_DstPortRange_MutualExclusion() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
+ Long dstPort = SINGLE_PORT;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
params.putAll(ClassifierTestUtils.createIntValueParam(L4ClassifierDefinition.DST_PORT_PARAM, dstPort));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("mutually exclusive");
+ thrown.expectMessage(Classifier.MSG_MUTUALLY_EXCLUSIVE);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void rangeValueMismatchTest() {
- matches.add(new MatchBuilder());
- Long dstRangeStart = Long.valueOf(8081);
- Long dstRangeEnd = Long.valueOf(8079);
+ public void testCheckPresenceOfRequiredParams_RangeValueMismatch() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ Long dstRangeStart = GREATER_RANGE_END;
+ Long dstRangeEnd = GREATER_RANGE_START;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.TCP));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Range value mismatch");
+ thrown.expectMessage(Classifier.MSG_RANGE_VALUE_MISMATCH);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void unsupportedProtocolTest() {
+ public void testUpdate_UnsupportedProtocol() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
matches.add(new MatchBuilder());
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM, 136));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not supported");
- matches = Classifier.L4_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_NOT_SUPPORTED);
+ Classifier.L4_CL.update(matches, params);
}
@Test
- public void classificationConflictTest() {
- matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createSctpDstPort(80)));
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
+ public void testUpdate_ClassificationConflict() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(new MatchBuilder().setLayer4Match(ClassifierTestUtils.createSctpDstPort(SINGLE_PORT_INT)));
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
ClassifierTestUtils.UDP));
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Classification conflict");
- matches = Classifier.L4_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
+ Classifier.L4_CL.update(matches, params);
}
@Test
- public void noProtoTest() {
+ public void testUpdate_NoProto() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
matches.add(new MatchBuilder());
- Long dstRangeStart = Long.valueOf(8079);
- Long dstRangeEnd = Long.valueOf(8081);
+ Long dstRangeStart = GREATER_RANGE_START;
+ Long dstRangeEnd = GREATER_RANGE_END;
params.putAll(ClassifierTestUtils.createRangeValueParam(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
dstRangeStart, dstRangeEnd));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage(IpProtoClassifierDefinition.PROTO_PARAM + " is missing");
- matches = Classifier.L4_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_IS_MISSING);
+ Classifier.L4_CL.update(matches, params);
}
@Test
- public void checkPresenceOfRequiredParameters1Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(L4ClassifierDefinition.SRC_PORT_PARAM,
- new ParameterValueBuilder().build()));
+ public void testCheckPresenceOfRequiredParameters_SrcPortNotSet() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ImmutableMap.of(L4ClassifierDefinition.SRC_PORT_PARAM, new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not specified");
+ thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters2Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(L4ClassifierDefinition.DST_PORT_PARAM,
- new ParameterValueBuilder().build()));
+ public void testCheckPresenceOfRequiredParameters_DstPortNotSet() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ImmutableMap.of(L4ClassifierDefinition.DST_PORT_PARAM, new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not specified");
+ thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters3Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
+ public void testCheckPresenceOfRequiredParameters_SrcRangeNotSet() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ImmutableMap.of(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM,
new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not present");
+ thrown.expectMessage(Classifier.MSG_NOT_PRESENT);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters4Test() {
- params.putAll(ImmutableMap.<String, ParameterValue>of(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
+ public void testCheckPresenceOfRequiredParameters_DstRangeNotSet() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ImmutableMap.of(L4ClassifierDefinition.DST_PORT_RANGE_PARAM,
new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("not present");
+ thrown.expectMessage(Classifier.MSG_NOT_PRESENT);
Classifier.L4_CL.checkPresenceOfRequiredParams(params);
}
}