/* * Copyright (c) 2015 Cable Television Laboratories, 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.pcmm.gates.impl; import org.pcmm.gates.ISessionClassID; /** * SessionClassID is a 1-byte unsigned integer value which identifies the proper admission control policy or * parameters to be applied for this Gate. The SessionClassID is a bit field, defined as follows: * Bit 0-2: Priority, a number from 0 to 7, where 0 is low priority and 7 is high. * Bit 3: Preemption, set to enable preemption of bandwidth allocated to lower priority sessions if necessary * (if supported). * Bit 4-7: Configurable, default to 0 */ public class SessionClassID implements ISessionClassID { /** * The priority field describes the relative importance of the session as compared to other sessions generated by * the same PDP. The PEP MAY use this value to both implement priority based admission (in conjunction with the * Preemption bit), and to defend the resulting flow from being preempted. */ private transient byte priority; /** * The preemption bit is used to by a PDP to direct the PEP to apply a priority-based admission control. Preemption * support is optional; a PEP MAY ignore this bit. If preemption is not requested by the PDP or not implement by the * PEP, then admission control policy will be on a first-come, first-served basis. */ private transient byte preemption; /** * The session ID value */ private byte session; /** * Constructor 1 * @param value - the session value */ public SessionClassID(byte value) { this.session = value; this.priority = 0; this.preemption = 0; priority |= value >> 2; preemption |= value >> 3; } /** * Constructor 2 * @param value - the session value * @param priority - overrides the default priority value of 2 * @param preemption - overrides the default preemption value of 3 */ public SessionClassID(byte value, final byte priority, final byte preemption) { this.session = value; this.priority = priority; this.preemption = preemption; } @Override public byte getPriority() { return priority; } @Override public byte getPreemption() { return preemption; } @Override public byte toSingleByte() { return session; } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof SessionClassID)) { return false; } final SessionClassID that = (SessionClassID) o; return priority == that.priority && preemption == that.preemption && session == that.session; } @Override public int hashCode() { int result = (int) priority; result = 31 * result + (int) preemption; result = 31 * result + (int) session; return result; } }