4 package org.pcmm.gates.impl;
6 import java.util.Arrays;
8 import org.pcmm.base.IPCMMBaseObject;
9 import org.pcmm.gates.IAMID;
10 import org.pcmm.gates.IClassifier;
11 import org.pcmm.gates.IGateID;
12 import org.pcmm.gates.IGateSpec;
13 import org.pcmm.gates.IPCMMError;
14 import org.pcmm.gates.IPCMMGate;
15 import org.pcmm.gates.ISubscriberID;
16 import org.pcmm.gates.ITrafficProfile;
17 import org.pcmm.gates.ITransactionID;
21 * <Gate-set>=<Decision Header><TransactionID><AMID> <SubscriberID> [<GateI>]
22 * <GateSpec> <Traffic Profile> <classifier>
25 public class PCMMGateReq implements IPCMMGate {
27 private boolean multicast;
28 private IGateID gateID;
30 private IPCMMError error;
31 private ISubscriberID subscriberID;
32 private ITransactionID transactionID;
33 private IGateSpec gateSpec;
34 private ITrafficProfile trafficProfile;
35 private IClassifier classifier;
37 public PCMMGateReq() {
40 public PCMMGateReq(byte[] data) {
44 sNum = sType = (byte) 0;
45 while (offset + 5 < data.length) {
47 len |= ((short) data[offset]) << 8;
48 len |= ((short) data[offset + 1]) & 0xFF;
49 sNum = data[offset + 2];
50 sType = data[offset + 3];
51 byte[] dataBuffer = Arrays.copyOfRange(data, offset, offset + len);
54 setGateID(new GateID(dataBuffer));
57 setAMID(new AMID(dataBuffer));
59 case ISubscriberID.SNUM:
60 setSubscriberID(new SubscriberID(dataBuffer));
62 case ITransactionID.SNUM:
63 setTransactionID(new TransactionID(dataBuffer));
66 setGateSpec(new GateSpec(dataBuffer));
68 case ITrafficProfile.SNUM:
69 setTrafficProfile(new BestEffortService(dataBuffer));
71 case IClassifier.SNUM:
72 setClassifier(new Classifier(dataBuffer));
75 error = new PCMMError(dataBuffer);
78 System.out.println("unhandled Object skept : S-NUM=" + sNum
79 + " S-TYPE=" + sType + " LEN=" + len);
88 * @see org.pcmm.gates.IPCMMGate#isMulticast()
91 public boolean isMulticast() {
92 // TODO Auto-generated method stub
99 * @see org.pcmm.gates.IPCMMGate#setGateID(short)
102 public void setGateID(IGateID gateid) {
103 this.gateID = gateid;
110 * @see org.pcmm.gates.IPCMMGate#setAMID(org.pcmm.gates.IAMID)
113 public void setAMID(IAMID iamid) {
121 * org.pcmm.gates.IPCMMGate#getSubscriberID(org.pcmm.gates.ISubscriberID)
124 public void setSubscriberID(ISubscriberID subscriberID) {
125 this.subscriberID = subscriberID;
131 * @see org.pcmm.gates.IPCMMGate#getGateSpec(org.pcmm.gates.IGateSpec)
134 public void setGateSpec(IGateSpec gateSpec) {
135 this.gateSpec = gateSpec;
141 * @see org.pcmm.gates.IPCMMGate#getClassifier(org.pcmm.gates.IClassifier)
144 public void setClassifier(IClassifier classifier) {
145 this.classifier = classifier;
152 * org.pcmm.gates.IPCMMGate#getTrafficProfile(org.pcmm.gates.ITrafficProfile
156 public void setTrafficProfile(ITrafficProfile profile) {
157 this.trafficProfile = profile;
163 * @see org.pcmm.gates.IPCMMGate#getGateID()
166 public IGateID getGateID() {
173 * @see org.pcmm.gates.IPCMMGate#getAMID()
176 public IAMID getAMID() {
183 * @see org.pcmm.gates.IPCMMGate#getSubscriberID()
186 public ISubscriberID getSubscriberID() {
193 * @see org.pcmm.gates.IPCMMGate#getGateSpec()
196 public IGateSpec getGateSpec() {
203 * @see org.pcmm.gates.IPCMMGate#getClassifier()
206 public IClassifier getClassifier() {
213 * @see org.pcmm.gates.IPCMMGate#getTrafficProfile()
216 public ITrafficProfile getTrafficProfile() {
217 return trafficProfile;
221 public void setTransactionID(ITransactionID transactionID) {
222 this.transactionID = transactionID;
226 public ITransactionID getTransactionID() {
227 return transactionID;
230 public IPCMMError getError() {
234 public void setError(IPCMMError error) {
239 public byte[] getData() {
240 byte[] array = new byte[0];
241 if (getTransactionID() != null) {
242 array = fill(array, getTransactionID());
244 if (getGateID() != null) {
245 array = fill(array, getGateID());
247 if (getAMID() != null) {
248 array = fill(array, getAMID());
251 if (getSubscriberID() != null) {
252 array = fill(array, getSubscriberID());
254 if (getGateSpec() != null) {
255 array = fill(array, getGateSpec());
257 if (getTrafficProfile() != null) {
258 array = fill(array, getTrafficProfile());
260 if (getClassifier() != null) {
261 array = fill(array, getClassifier());
266 private byte[] fill(byte[] array, IPCMMBaseObject obj) {
267 byte[] a = obj.getAsBinaryArray();
268 int offset = array.length;
269 array = Arrays.copyOf(array, offset + a.length);
270 System.arraycopy(a, 0, array, offset, a.length);