2 * Copyright (c) 2015 Cable Television Laboratories, 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.pcmm.gates.impl;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.pcmm.gates.IExtendedClassifier;
13 import org.pcmm.gates.IExtendedClassifier.ActivationState;
14 import org.pcmm.gates.IIPv6Classifier.FlowLabel;
16 import java.net.Inet6Address;
17 import java.net.InetAddress;
18 import java.net.UnknownHostException;
21 * Tests the data holder class ExtendedClassifier.
23 public class IPv6ClassifierTest {
25 @Test(expected = IllegalArgumentException.class)
26 public void nullSrcAddr() throws UnknownHostException {
27 new IPv6Classifier(null, (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
28 (short)1, (short)2, (byte)4, (short)5, (short)6, (short)7, ActivationState.ACTIVE, IExtendedClassifier.Action.ADD,
29 FlowLabel.VALID, (byte)11, (byte)12, (byte)13, 14, (short)15, (byte)16, (byte)17);
32 @Test(expected = IllegalArgumentException.class)
33 public void nullDstAddr() throws UnknownHostException {
34 new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
35 null, (short)1, (short)2, (byte)4, (short)5, (short)6, (short)7, ActivationState.ACTIVE, IExtendedClassifier.Action.ADD,
36 FlowLabel.VALID, (byte)11, (byte)12, (byte)13, 14, (short)15, (byte)16, (byte)17);
39 @Test(expected = IllegalArgumentException.class)
40 public void nullActivationState() throws UnknownHostException {
41 new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
42 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"), (short)1, (short)2, (byte)4, (short)5,
43 (short)6, (short)7, null, IExtendedClassifier.Action.ADD, FlowLabel.VALID, (byte)11, (byte)12, (byte)13, 14, (short)15,
47 @Test(expected = IllegalArgumentException.class)
48 public void nullAction() throws UnknownHostException {
49 new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
50 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"), (short)1, (short)2, (byte)4, (short)5,
51 (short)6, (short)7, ActivationState.ACTIVE, null, FlowLabel.VALID, (byte)11, (byte)12, (byte)13, 14, (short)15,
55 @Test(expected = IllegalArgumentException.class)
56 public void nullFlowLabel() throws UnknownHostException {
57 new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
58 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"), (short)1, (short)2, (byte)4, (short)5,
59 (short)6, (short)7, ActivationState.ACTIVE, IExtendedClassifier.Action.ADD, null, (byte)11, (byte)12, (byte)13, 14, (short)15,
64 public void constructionActiveValid() throws UnknownHostException {
65 final IPv6Classifier classifier = new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
66 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
67 (short)11, (short)12, (byte)14, (short)15, (short)16, (short)17, ActivationState.ACTIVE, IExtendedClassifier.Action.ADD,
68 FlowLabel.VALID, (byte)21, (byte)22, (byte)23, 24, (short)25, (byte)26, (byte)27);
70 Assert.assertNull(classifier.getProtocol());
72 Assert.assertEquals((byte) 0, classifier.getDSCPTOS());
74 Assert.assertEquals(InetAddress.getByName("00:00:00:00:00:00:00:01"), classifier.getSourceIPAddress());
75 Assert.assertEquals(InetAddress.getByName("00:00:00:00:00:00:00:01"), classifier.getDestinationIPAddress());
76 Assert.assertEquals((short) 11, classifier.getSourcePort());
77 Assert.assertEquals((short) 12, classifier.getDestinationPort());
78 Assert.assertEquals((byte) 14, classifier.getPriority());
79 Assert.assertEquals((short) 15, classifier.getSourcePortEnd());
80 Assert.assertEquals((short) 16, classifier.getDestinationPortEnd());
81 Assert.assertEquals((short) 17, classifier.getClassifierID());
82 Assert.assertEquals(ActivationState.ACTIVE, classifier.getActivationState());
83 Assert.assertEquals(IExtendedClassifier.Action.ADD, classifier.getAction());
84 Assert.assertEquals(FlowLabel.VALID, classifier.getFlowLabelEnableFlag());
85 Assert.assertEquals((byte) 21, classifier.getTcLow());
86 Assert.assertEquals((byte) 22, classifier.getTcHigh());
87 Assert.assertEquals((byte) 23, classifier.getTcMask());
88 Assert.assertEquals(24, classifier.getFlowLabel());
89 Assert.assertEquals((short)25, classifier.getNextHdr());
90 Assert.assertEquals((byte)26, classifier.getSourcePrefixLen());
91 Assert.assertEquals((byte)27, classifier.getDestinationPrefixLen());
95 public void constructionInactiveIrrelevant() throws UnknownHostException {
96 final IPv6Classifier classifier = new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
97 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
98 (short)11, (short)12, (byte)14, (short)15, (short)16, (short)17, ActivationState.INACTIVE, IExtendedClassifier.Action.ADD,
99 FlowLabel.IRRELEVANT, (byte)21, (byte)22, (byte)23, 24, (short)25, (byte)26, (byte)27);
101 Assert.assertNull(classifier.getProtocol());
103 Assert.assertEquals((byte) 0, classifier.getDSCPTOS());
105 Assert.assertEquals(InetAddress.getByName("00:00:00:00:00:00:00:01"), classifier.getSourceIPAddress());
106 Assert.assertEquals(InetAddress.getByName("00:00:00:00:00:00:00:01"), classifier.getDestinationIPAddress());
107 Assert.assertEquals((short) 11, classifier.getSourcePort());
108 Assert.assertEquals((short) 12, classifier.getDestinationPort());
109 Assert.assertEquals((byte) 14, classifier.getPriority());
110 Assert.assertEquals((short) 15, classifier.getSourcePortEnd());
111 Assert.assertEquals((short) 16, classifier.getDestinationPortEnd());
112 Assert.assertEquals((short) 17, classifier.getClassifierID());
113 Assert.assertEquals(ActivationState.INACTIVE, classifier.getActivationState());
114 Assert.assertEquals(IExtendedClassifier.Action.ADD, classifier.getAction());
115 Assert.assertEquals(FlowLabel.IRRELEVANT, classifier.getFlowLabelEnableFlag());
116 Assert.assertEquals((byte) 21, classifier.getTcLow());
117 Assert.assertEquals((byte) 22, classifier.getTcHigh());
118 Assert.assertEquals((byte) 23, classifier.getTcMask());
120 // Per specs, this value must be 0 when IRRELEVANT
121 Assert.assertEquals(0, classifier.getFlowLabel());
123 Assert.assertEquals((short)25, classifier.getNextHdr());
124 Assert.assertEquals((byte)26, classifier.getSourcePrefixLen());
125 Assert.assertEquals((byte)27, classifier.getDestinationPrefixLen());
129 public void byteParsingActiveValid() throws UnknownHostException {
130 final IPv6Classifier classifier = new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
131 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
132 (short)21, (short)22, (byte)24, (short)25, (short)26, (short)27, ActivationState.ACTIVE, IExtendedClassifier.Action.ADD,
133 FlowLabel.VALID, (byte)31, (byte)32, (byte)33, 34, (short)35, (byte)36, (byte)37);
134 final IPv6Classifier parsed = IPv6Classifier.parse(classifier.getBytes());
135 Assert.assertEquals(classifier, parsed);
139 public void byteParsingInactiveIrrelevant() throws UnknownHostException {
140 final IPv6Classifier classifier = new IPv6Classifier((Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
141 (Inet6Address)InetAddress.getByName("00:00:00:00:00:00:00:01"),
142 (short)21, (short)22, (byte)24, (short)25, (short)26, (short)27, ActivationState.INACTIVE, IExtendedClassifier.Action.ADD,
143 FlowLabel.IRRELEVANT, (byte)31, (byte)32, (byte)33, 34, (short)35, (byte)36, (byte)37);
144 final IPv6Classifier parsed = IPv6Classifier.parse(classifier.getBytes());
145 Assert.assertEquals(classifier, parsed);