4 package org.pcmm.gates.impl;
6 import java.util.Arrays;
8 // import org.junit.Assert;
9 import org.pcmm.base.impl.PCMMBaseObject;
10 import org.pcmm.gates.ITrafficProfile;
11 import org.umu.cops.stack.COPSData;
16 public class BestEffortService extends PCMMBaseObject implements
18 public static final byte STYPE = 3;
19 // XXX -> 60=0x3C, 112 = 0x70, 164=0xA4
20 // Length = 44=0x2C, 80=0x50 or 116=0x74
21 public static final short LENGTH = 44;
23 public static final byte DEFAULT_TRAFFIC_PRIORITY = 0;
25 public static final byte DEFAULT_ENVELOP = 0x7;
27 public static final int DEFAULT_MAX_TRAFFIC_BURST = 3044;
29 private BEEnvelop authorizedEnvelop;
31 private BEEnvelop reservedEnvelop;
33 private BEEnvelop committedEnvelop;
40 public BestEffortService(byte e) {
41 super((short) (e == 1 ? LENGTH : (e == 7 ? 116 : 80)), STYPE, SNUM);
43 authorizedEnvelop = new BEEnvelop();
45 reservedEnvelop = new BEEnvelop();
47 committedEnvelop = new BEEnvelop();
51 public BestEffortService(byte[] bytes) {
53 byte e = getEnvelop();
54 authorizedEnvelop = new BEEnvelop(headPadding(offset, Arrays.copyOfRange(bytes, 8, LENGTH)));
56 reservedEnvelop = new BEEnvelop(headPadding(offset, Arrays.copyOfRange(bytes, LENGTH, 80)));
58 committedEnvelop = new BEEnvelop(headPadding(offset, Arrays.copyOfRange(bytes, 80, 116)));
63 public void setEnvelop(byte e) {
64 setLength((short) (e == 1 ? LENGTH : (e == 7 ? 116 : 80)));
65 // reset cops data to fit the new length
66 byte[] array = new byte[getLength() - offset];
67 Arrays.fill(array, (byte) 0);
68 setData(new COPSData(array, 0, array.length));
69 setByte(e, (short) 0);
73 public byte getEnvelop() {
74 return getByte((short) 0);
77 public BEEnvelop getAuthorizedEnvelop() {
78 return authorizedEnvelop;
81 public BEEnvelop getReservedEnvelop() {
82 return reservedEnvelop;
85 public BEEnvelop getCommittedEnvelop() {
86 return committedEnvelop;
90 public byte[] getAsBinaryArray() {
91 byte[] returnBuffer = super.getAsBinaryArray();
93 {// fill buffer with the Authorized Envelop
94 byte[] authEnv = Arrays.copyOfRange(getAuthorizedEnvelop().getAsBinaryArray(), offset, BEEnvelop.LENGHT);
95 // offset + 4 since the Envelop data begin from byte nb 8
96 System.arraycopy(authEnv, 0, returnBuffer, offset + 4, authEnv.length);
98 if (getReservedEnvelop() != null) {
99 byte[] reservedEnv = Arrays.copyOfRange(getReservedEnvelop().getAsBinaryArray(), offset, BEEnvelop.LENGHT);
100 System.arraycopy(reservedEnv, 0, returnBuffer, LENGTH, reservedEnv.length);
102 if (getCommittedEnvelop() != null) {
103 byte[] commitEnv = Arrays.copyOfRange(getCommittedEnvelop().getAsBinaryArray(), offset, BEEnvelop.LENGHT);
104 System.arraycopy(commitEnv, 0, returnBuffer, LENGTH + 36, commitEnv.length);
113 public static class BEEnvelop extends PCMMBaseObject {
114 // basically we need 36 bytes but since PCMMBasedObject needs 4 bytes
115 // more we allocate 40 bytes and then subtract them when setting BE
117 private final static short LENGHT = 40;
119 protected BEEnvelop() {
120 super(LENGHT, (byte) 0, (byte) 0);
121 setTrafficPriority(DEFAULT_TRAFFIC_PRIORITY);
124 protected BEEnvelop(byte[] buffer) {
128 public void setTrafficPriority(byte p) {
129 setByte(p, (short) 0);
132 public byte getTrafficPriority() {
133 return getByte((short) 0);
137 public void setRequestTransmissionPolicy(int p) {
138 setInt(p, (short) 4);
141 public int getRequestTransmissionPolicy() {
142 return getInt((short) 4);
145 public int getMaximumSustainedTrafficRate() {
146 return getInt((short) 8);
149 public void setMaximumSustainedTrafficRate(int p) {
150 setInt(p, (short) 8);
153 public int getMaximumTrafficBurst() {
154 return getInt((short) 12);
157 public void setMaximumTrafficBurst(int p) {
158 setInt(p, (short) 12);
161 public int getMinimumReservedTrafficRate() {
162 return getInt((short) 16);
165 public void setMinimumReservedTrafficRate(int p) {
166 setInt(p, (short) 16);
169 public short getAssumedMinimumReservedTrafficRatePacketSize() {
170 return getShort((short) 20);
173 public void setAssumedMinimumReservedTrafficRatePacketSize(short p) {
174 setShort(p, (short) 20);
177 public short getMaximumConcatenatedBurst() {
178 return getShort((short) 22);
181 public void setMaximumConcatenatedBurst(short p) {
182 setShort(p, (short) 22);
185 public int getRequiredAttributeMask() {
186 return getInt((short) 24);
189 public void setRequiredAttributeMask(int p) {
190 setInt(p, (short) 24);
193 public int getForbiddenAttributeMask() {
194 return getInt((short) 28);
197 public void setForbiddenAttributeMask(int p) {
198 setInt(p, (short) 28);
201 public int getAttributeAggregationRuleMask() {
202 return getInt((short) 32);
205 public void setAttributeAggregationRuleMask(int p) {
206 setInt(p, (short) 32);