All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.tid.pce.pcep.objects.BandwidthExistingLSPGeneralizedBandwidth Maven / Gradle / Ivy

The newest version!
package es.tid.pce.pcep.objects;

import java.util.LinkedList;

import es.tid.pce.pcep.PCEPProtocolViolationException;
import es.tid.pce.pcep.constructs.GeneralizedBandwidth;
import es.tid.pce.pcep.constructs.GeneralizedBandwidthSSON;
import es.tid.pce.pcep.objects.tlvs.PCEPTLV;


/**
 * Generalized bandwidth of an existing TE-LSP for which a reoptimization is requested 
 * @see RFC 87791 Section 2.3
 * @author ogondio
 *
 */
public class BandwidthExistingLSPGeneralizedBandwidth extends Bandwidth{
	
	/*
	 *  *  
 *  *    0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |    Bandwidth Spec Length      | Rev. Bandwidth Spec Length    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      | Bw Spec Type  |   Reserved                                    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      ~                     generalized bandwidth                     ~
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      ~          Optional : reverse generalized bandwidth             ~
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      ~                       Optional TLVs                           ~
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	 */
	
	protected int bwSpecLength = 0;
	public int getBwSpecLength() {
		return bwSpecLength;
	}
	public void setBwSpecLength(int bwSpecLength) {
		this.bwSpecLength = bwSpecLength;
	}
	public int getRevBwSpecLength() {
		return revBwSpecLength;
	}
	public void setRevBwSpecLength(int revBwSpecLength) {
		this.revBwSpecLength = revBwSpecLength;
	}
	public int getBwSpecType() {
		return bwSpecType;
	}
	public void setBwSpecType(int bwSpecType) {
		this.bwSpecType = bwSpecType;
	}
//	public LinkedList getOptionalTLVs() {
//		return optionalTLVs;
//	}
//	public void setOptionalTLVs(LinkedList optionalTLVs) {
//		this.optionalTLVs = optionalTLVs;
//	}
	protected int revBwSpecLength =0;
	protected int bwSpecType;
	
	protected GeneralizedBandwidth generalizedBandwidth;
	protected GeneralizedBandwidth reverseGeneralizedBandwidth;
		
	//private LinkedList optionalTLVs;
	
	public BandwidthExistingLSPGeneralizedBandwidth(){
		super();
		this.setOT(ObjectParameters.PCEP_OBJECT_TYPE_BANDWIDTH_GEN_BW_EXISTING_TE_LSP);
	}
	public BandwidthExistingLSPGeneralizedBandwidth (byte[] bytes, int offset) throws MalformedPCEPObjectException{
		super(bytes, offset);
		decode();
	}
	
	public void encode() {
		int length=12;
		if (generalizedBandwidth!=null) {
			try {
				generalizedBandwidth.encode();
			} catch (PCEPProtocolViolationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			bwSpecLength=generalizedBandwidth.getLength();
			System.out.println("BW SPC "+bwSpecLength);
			length =length+generalizedBandwidth.getLength();
			bwSpecType=generalizedBandwidth.getBwSpecType();
			
		}
		if (reverseGeneralizedBandwidth!=null) {
			try {
				reverseGeneralizedBandwidth.encode();
			} catch (PCEPProtocolViolationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			revBwSpecLength=reverseGeneralizedBandwidth.getLength();
			length =length+reverseGeneralizedBandwidth.getLength();

		}
		
//		for (int k=0; k>8)&0xFF);
		this.getBytes()[offset+1]=(byte) (bwSpecLength&0xFF);
		this.getBytes()[offset+2]=(byte) ((revBwSpecLength>>8)&0xFF);
		this.getBytes()[offset+3]=(byte) (revBwSpecLength&0xFF);
		this.getBytes()[offset+4]=(byte)bwSpecType;
		offset=12;
		if (generalizedBandwidth!=null) {
			System.arraycopy(generalizedBandwidth.getBytes(), 0, this.getBytes(), offset, generalizedBandwidth.getLength());
			offset=offset+generalizedBandwidth.getLength();
			
		}
		if (reverseGeneralizedBandwidth!=null) {
			System.arraycopy(reverseGeneralizedBandwidth.getBytes(), 0, this.getBytes(), offset, reverseGeneralizedBandwidth.getLength());
			offset=offset+reverseGeneralizedBandwidth.getLength();
			
		}
//		if (optionalTLVs!=null){
//			for (int k=0 ; k




© 2015 - 2024 Weber Informatics LLC | Privacy Policy