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

es.tid.pce.pcep.constructs.Response Maven / Gradle / Ivy

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

import java.util.LinkedList;

import es.tid.pce.pcep.PCEPProtocolViolationException;
import es.tid.pce.pcep.objects.Bandwidth;
import es.tid.pce.pcep.objects.BandwidthExistingLSP;
import es.tid.pce.pcep.objects.BandwidthExistingLSPGeneralizedBandwidth;
import es.tid.pce.pcep.objects.BandwidthRequested;
import es.tid.pce.pcep.objects.BandwidthRequestedGeneralizedBandwidth;
import es.tid.pce.pcep.objects.IncludeRouteObject;
import es.tid.pce.pcep.objects.LSPA;
import es.tid.pce.pcep.objects.MalformedPCEPObjectException;
import es.tid.pce.pcep.objects.Metric;
import es.tid.pce.pcep.objects.Monitoring;
import es.tid.pce.pcep.objects.NoPath;
import es.tid.pce.pcep.objects.ObjectParameters;
import es.tid.pce.pcep.objects.PCEPObject;
import es.tid.pce.pcep.objects.PccReqId;
import es.tid.pce.pcep.objects.RequestParameters;
import es.tid.pce.pcep.objects.ReservationConf;

/**
 * Represents a PCEP Response.  
 * 

It is a collection of PCEP Objects.

*

From RFC 5440 Section 6.5 :

* {@code * ::= [] [] [] ::=[] ::= where: ::=[] [] [] --ESTADO DRAFT [] [] ::=[] The PCRep message MUST contain at least one RP object. For each reply that is bundled into a single PCReq message, an RP object MUST be included that contains a Request-ID-number identical to the one specified in the RP object carried in the corresponding PCReq message (see Section 7.4 for the definition of the RP object). * * * With monitoring data: * ::= [] [] [] []} * * @author Oscar Gonzalez de Dios * */ public class Response extends PCEPConstruct{ /** * */ private RequestParameters requestParameters; /** * Monitoring object */ private Monitoring monitoring; /** * */ private PccReqId pccIdreq; /** * */ private NoPath noPath; /** * */ private LSPA lSPA; /** * */ private Bandwidth bandwidth; /** * */ private LinkedList metricList; /** * */ private IncludeRouteObject iRO; private ReservationConf resConf; /** * */ private LinkedList pathList; /** * */ private LinkedList metricPCEList; public Response() { metricList=new LinkedList(); pathList=new LinkedList(); metricPCEList=new LinkedList(); } public Response(byte[] bytes, int offset) throws PCEPProtocolViolationException { metricList=new LinkedList(); pathList=new LinkedList(); metricPCEList=new LinkedList(); decode(bytes,offset); } public RequestParameters getRequestParameters() { return requestParameters; } public void setRequestParameters(RequestParameters requestParameters) { this.requestParameters = requestParameters; } public NoPath getNoPath() { return noPath; } public void setNoPath(NoPath noPath) { this.noPath = noPath; } public LSPA getLSPA() { return lSPA; } public void setLSPA(LSPA lSPA) { this.lSPA = lSPA; } public Bandwidth getBandwidth() { return bandwidth; } public void setBandwidth(Bandwidth bandwidth) { this.bandwidth = bandwidth; } public LinkedList getMetricList() { return metricList; } public void setMetricList(LinkedList metricList) { this.metricList = metricList; } public IncludeRouteObject getIRO() { return iRO; } public void setIRO(IncludeRouteObject iRO) { this.iRO = iRO; } public LinkedList getPathList() { return pathList; } public void addPath(Path path){ this.pathList.add(path); } public Path getPath(int index){ return this.pathList.get(index); } public void setPathList(LinkedList pathList) { this.pathList = pathList; } public Monitoring getMonitoring() { return monitoring; } public void setMonitoring(Monitoring monitoring) { this.monitoring = monitoring; } public PccReqId getPccIdreq() { return pccIdreq; } public void setPccIdreq(PccReqId pccIdreq) { this.pccIdreq = pccIdreq; } public LinkedList getMetricPCEList() { return metricPCEList; } public void setMetricPCEList(LinkedList metricPCEList) { this.metricPCEList = metricPCEList; } public ReservationConf getResConf() { return resConf; } public void setResConf(ReservationConf resConf) { this.resConf = resConf; } public void encode() throws PCEPProtocolViolationException { int len=0; if (requestParameters!=null){ requestParameters.encode(); len=len+requestParameters.getLength(); } else { log.warn("requestParameters is compulsory in response"); throw new PCEPProtocolViolationException(); } if (monitoring!=null){ monitoring.encode(); len=len+monitoring.getLength(); } if (pccIdreq!=null){ pccIdreq.encode(); len=len+pccIdreq.getLength(); } if (noPath!=null){ noPath.encode(); len=len+noPath.getLength(); } if (lSPA!=null){ lSPA.encode(); len=len+lSPA.getLength(); } if (bandwidth!=null){ bandwidth.encode(); len=len+bandwidth.getLength(); } if (metricList!=null){ for (int i=0;i=bytes.length){ this.setLength(len); return; } } else { log.warn("Request must start with RP object"); throw new PCEPProtocolViolationException(); } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_MONITORING){ try { monitoring=new Monitoring(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed Monitoring Object found"); throw new PCEPProtocolViolationException(); } offset=offset+monitoring.getLength(); len=len+monitoring.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_PCC_REQ_ID){ try { pccIdreq=new PccReqId(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed PCC ID REQ Object found"); throw new PCEPProtocolViolationException(); } offset=offset+pccIdreq.getLength(); len=len+pccIdreq.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_NOPATH){ try { noPath=new NoPath(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed NOPATH Object found"); throw new PCEPProtocolViolationException(); } offset=offset+noPath.getLength(); len=len+noPath.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_LSPA){ try { lSPA=new LSPA(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed LSPA Object found"); throw new PCEPProtocolViolationException(); } offset=offset+lSPA.getLength(); len=len+lSPA.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } } // Bandwidth try { oc = PCEPObject.getObjectClass(bytes, offset); ot = PCEPObject.getObjectType(bytes, offset); if (oc == ObjectParameters.PCEP_OBJECT_CLASS_BANDWIDTH) { if (ot == ObjectParameters.PCEP_OBJECT_TYPE_BANDWIDTH_REQUEST) { bandwidth = new BandwidthRequested(bytes, offset); } else if (ot == ObjectParameters.PCEP_OBJECT_TYPE_BANDWIDTH_EXISTING_TE_LSP) { bandwidth = new BandwidthExistingLSP(bytes, offset); } else if (ot == ObjectParameters.PCEP_OBJECT_TYPE_BANDWIDTH_GEN_BW_REQUEST) { bandwidth = new BandwidthRequestedGeneralizedBandwidth(bytes, offset); } else if (ot == ObjectParameters.PCEP_OBJECT_TYPE_BANDWIDTH_GEN_BW_EXISTING_TE_LSP) { bandwidth = new BandwidthExistingLSPGeneralizedBandwidth(bytes, offset); } else { log.warn("Malformed BANDWIDTH Object found"); throw new PCEPProtocolViolationException(); } offset = offset + bandwidth.getLength(); len = len + bandwidth.getLength(); if (offset >= bytes.length) { this.setLength(len); return; } } } catch (MalformedPCEPObjectException e) { log.warn("Malformed BANDWIDTH Object found"); throw new PCEPProtocolViolationException(); } //Metric oc=PCEPObject.getObjectClass(bytes, offset); while (oc==ObjectParameters.PCEP_OBJECT_CLASS_METRIC){ Metric metric; try { metric = new Metric(bytes,offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed METRIC Object found"); throw new PCEPProtocolViolationException(); } metricList.add(metric); offset=offset+metric.getLength(); len=len+metric.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } oc=PCEPObject.getObjectClass(bytes, offset); } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_IRO){ try { iRO=new IncludeRouteObject(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed IRO Object found"); throw new PCEPProtocolViolationException(); } offset=offset+iRO.getLength(); len=len+iRO.getLength(); if ((offset+len)>=bytes.length){ this.setLength(len); return; } } oc=PCEPObject.getObjectClass(bytes, offset); if (oc==ObjectParameters.PCEP_OBJECT_CLASS_RESERVATION_CONF){ try { resConf=new ReservationConf(bytes, offset); } catch (MalformedPCEPObjectException e) { log.warn("Malformed RESERVATION CONF Object found"); throw new PCEPProtocolViolationException(); } offset=offset+resConf.getLength(); len=len+resConf.getLength(); if ((offset+len)>=bytes.length){ this.setLength(len); return; } } oc=PCEPObject.getObjectClass(bytes, offset); while (oc==ObjectParameters.PCEP_OBJECT_CLASS_ERO){ Path path=new Path(bytes,offset); pathList.add(path); offset=offset+path.getLength(); len=len+path.getLength(); if (offset>=bytes.length){ this.setLength(len); return; } oc=PCEPObject.getObjectClass(bytes, offset); } oc=PCEPObject.getObjectClass(bytes, offset); while (oc==ObjectParameters.PCEP_OBJECT_CLASS_PCE_ID){ MetricPCE metricPCE=new MetricPCE(bytes,offset); metricPCEList.add(metricPCE); offset=offset+metricPCE.getLength(); len=len+metricPCE.getLength(); if ((offset+len)>=bytes.length){ this.setLength(len); return; } oc=PCEPObject.getObjectClass(bytes, offset); } this.setLength(len); } public String toString(){ String ret=""; if (requestParameters!=null){ ret=ret+requestParameters.toString(); } if (noPath!=null){ ret=ret+""; } if (lSPA!=null){ ret=ret+""; } if (bandwidth!=null){ ret=ret+""; } if (metricList!=null){ for (int i=0;i"; } if (pathList!=null){ for (int i=0;i





© 2015 - 2024 Weber Informatics LLC | Privacy Policy