3 * Copyright (c) 2014 CableLabs. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.pcmm.gates.impl;
12 import org.pcmm.base.impl.PCMMBaseObject;
13 import org.pcmm.gates.IIPv6Classifier;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 import java.net.InetAddress;
18 import java.net.UnknownHostException;
23 public class IPv6Classifier extends PCMMBaseObject implements
26 private Logger logger = LoggerFactory.getLogger(IPv6Classifier.class);
28 public IPv6Classifier() {
29 this(LENGTH, STYPE, SNUM);
33 * @param data - the data bytes to parse
35 public IPv6Classifier(byte[] data) {
40 * @param len - the classifier's length
41 * @param sType - the sType value
42 * @param sNum - the sNum value
44 public IPv6Classifier(short len, byte sType, byte sNum) {
45 super(len, sType, sNum);
48 // offset:length Field Name: Description
49 // 00:01 Flags: 0000.0001 Flow Label enable match
53 // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
54 // 08:02 Next Header Type
55 // 10:01 Source Prefix Length
56 // 11:01 Destination Prefix Length
57 // 12:16 IPv6 Source Address
58 // 28:16 IPv6 Destination Address
59 // 44:02 Source Port Start
60 // 46:02 Source Port End
61 // 48:02 Destination Port Start
62 // 50:02 Destination Port End
65 // 55:01 Activation State
69 // 00:01 Flags: 0000.0001 Flow Label enable match
71 public void setFlowLabelEnableFlag(byte flag) {
72 setByte(flag, (short) 0);
75 public byte getFlowLabelEnableFlag() {
76 return getByte((short) 0);
81 public void setTcLow(byte tcLow) {
82 setByte(tcLow, (short) 1);
85 public byte getTcLow() {
86 return getByte((short) 1);
91 public void setTcHigh(byte tcHigh) {
92 setByte(tcHigh, (short) 2);
95 public byte getTcHigh() {
96 return getByte((short) 2);
101 public void setTcMask(byte tcMask) {
102 setByte(tcMask, (short) 3);
105 public byte getTcMask() {
106 return getByte((short) 3);
109 // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
111 public void setFlowLabel(Long flowLabel) {
112 setInt(flowLabel.intValue(), (short) 4);
115 public int getFlowLabel() {
116 return getInt((short) 4);
119 // 08:02 Next Header Type
121 public void setNextHdr(short nxtHdr) {
122 setShort(nxtHdr, (short) 8);
125 public short getNextHdr() {
126 return getShort((short) 8);
129 // 10:01 Source Prefix Length
131 public void setSourcePrefixLen(byte srcPrefixLen) {
132 setByte(srcPrefixLen, (short) 10);
135 public byte getSourcePrefixLen() {
136 return getByte((short) 10);
139 // 11:01 Destination Prefix Length
141 public void setDestinationPrefixLen(byte dstPrefixLen) {
142 setByte(dstPrefixLen, (short) 11);
145 public byte getDestinationPrefixLen() {
146 return getByte((short) 11);
149 // 12:16 IPv6 Source Address
151 public void setSourceIPAddress(InetAddress a) {
152 setBytes(a.getAddress(), (short) 12);
155 public InetAddress getSourceIPAddress() {
157 return InetAddress.getByAddress(getBytes((short) 12, (short) 16));
158 } catch (UnknownHostException e) {
159 logger.error("getSourceIPAddress(): Malformed IPv6 address: {}", e.getMessage());
164 // 28:16 IPv6 Destination Address
166 public void setDestinationIPAddress(InetAddress a) {
167 setBytes(a.getAddress(), (short) 28);
170 public InetAddress getDestinationIPAddress() {
172 return InetAddress.getByAddress(getBytes((short) 28, (short) 16));
173 } catch (UnknownHostException e) {
174 logger.error("getDestinationIPAddress(): Malformed IPv6 address: {}", e.getMessage());
178 // 44:02 Source Port Start
180 public short getSourcePortStart() {
181 return getShort((short) 44);
184 public void setSourcePortStart(short p) {
185 setShort(p, (short) 44);
188 // 46:02 Source Port End
190 public short getSourcePortEnd() {
191 return getShort((short) 46);
194 public void setSourcePortEnd(short p) {
195 setShort(p, (short) 46);
198 // 48:02 Destination Port Start
200 public short getDestinationPortStart() {
201 return getShort((short) 48);
204 public void setDestinationPortStart(short p) {
205 setShort(p, (short) 48);
208 // 50:02 Destination Port End
210 public short getDestinationPortEnd() {
211 return getShort((short) 50);
214 public void setDestinationPortEnd(short p) {
215 setShort(p, (short) 50);
218 // 52:02 ClassifierID
220 public short getClassifierID() {
221 return getShort((short) 52);
225 public void setClassifierID(short p) {
226 setShort(p, (short) 52);
231 public void setPriority(byte p) {
232 setByte(p, (short) 54);
235 public byte getPriority() {
236 return getByte((short) 54);
239 // 55:01 Activation State
241 public void setActivationState(byte s) {
242 setByte(s, (short) 55);
245 public byte getActivationState() {
246 return getByte((short) 55);
251 public void setAction(byte a) {
252 setByte(a, (short) 56);
255 public byte getAction() {
256 return getByte((short) 56);
261 // baggage from IExtendedClassifier
262 // not used in IPv6 classifiers
264 public void setIPSourceMask(InetAddress a) {
265 // TODO Auto-generated method stub
270 public void setIPDestinationMask(InetAddress m) {
271 // TODO Auto-generated method stub
276 public InetAddress getIPSourceMask() {
277 // TODO Auto-generated method stub
282 public InetAddress getIPDestinationMask() {
283 // TODO Auto-generated method stub
288 public short getDestinationPort() {
289 // TODO Auto-generated method stub
294 public void setDestinationPort(short p) {
295 // TODO Auto-generated method stub
300 public short getSourcePort() {
301 // TODO Auto-generated method stub
306 public void setSourcePort(short p) {
307 // TODO Auto-generated method stub
312 public short getProtocol() {
313 // TODO Auto-generated method stub
318 public void setProtocol(short p) {
319 // TODO Auto-generated method stub
324 public byte getDSCPTOS() {
325 // TODO Auto-generated method stub
330 public void setDSCPTOS(byte v) {
331 // TODO Auto-generated method stub
336 public byte getDSCPTOSMask() {
337 // TODO Auto-generated method stub
342 public void setDSCPTOSMask(byte v) {
343 // TODO Auto-generated method stub