mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-12-18 07:41:47 +01:00
Implementation of PcInitate and PcUpdate messages
Change-Id: I746a5860a8b4a8022d747a02075ed3237741c53a
This commit is contained in:
parent
ffc5bbc55b
commit
f7364db058
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ dependency-reduced-pom.xml
|
|||||||
|
|
||||||
core/store/trivial/data/
|
core/store/trivial/data/
|
||||||
core/store/apps
|
core/store/apps
|
||||||
|
/bin/
|
||||||
|
|||||||
3
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepCloseMsg.java
Executable file → Normal file
3
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepCloseMsg.java
Executable file → Normal file
@ -19,6 +19,7 @@ package org.onosproject.pcepio.protocol;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
import org.onosproject.pcepio.types.PcepObjectHeader;
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
import org.onosproject.pcepio.types.PcepValueType;
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ public interface PcepCloseMsg extends PcepObject, PcepMessage {
|
|||||||
void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv);
|
void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void writeTo(ChannelBuffer channelBuffer);
|
void writeTo(ChannelBuffer channelBuffer) throws PcepParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder interface with get and set functions to build Close message.
|
* Builder interface with get and set functions to build Close message.
|
||||||
|
|||||||
13
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactories.java
Executable file → Normal file
13
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactories.java
Executable file → Normal file
@ -18,6 +18,7 @@ package org.onosproject.pcepio.protocol;
|
|||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.onosproject.pcepio.exceptions.PcepParseException;
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -35,15 +36,15 @@ public final class PcepFactories {
|
|||||||
/*
|
/*
|
||||||
* Returns the instance of PCEP Version.
|
* Returns the instance of PCEP Version.
|
||||||
*
|
*
|
||||||
* @param version
|
* @param version PCEP version
|
||||||
* @return PCEP version
|
* @return PCEP version
|
||||||
*/
|
*/
|
||||||
public static PcepFactory getFactory(PcepVersion version) {
|
public static PcepFactory getFactory(PcepVersion version) {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case PCEP_1:
|
case PCEP_1:
|
||||||
// TODO : to get the pcep version 1 factory
|
return PcepFactoryVer1.INSTANCE;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("[PcepFactory:]Unknown version: " + version);
|
throw new IllegalArgumentException("Unknown version: " + version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,6 @@ public final class PcepFactories {
|
|||||||
public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException {
|
public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException {
|
||||||
|
|
||||||
if (!bb.readable()) {
|
if (!bb.readable()) {
|
||||||
log.debug("Empty message received");
|
|
||||||
throw new PcepParseException("Empty message received");
|
throw new PcepParseException("Empty message received");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,13 +75,12 @@ public final class PcepFactories {
|
|||||||
switch (packetVersion) {
|
switch (packetVersion) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// TODO : get the factory for version 1
|
factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown Packet version: " + packetVersion);
|
throw new IllegalArgumentException("Unknown Packet version: " + packetVersion);
|
||||||
}
|
}
|
||||||
// TODO : Read the PCEP message from the factory
|
return factory.getReader().readFrom(bb);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,323 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepAttribute;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEndPointsObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEroObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides PcInitiatedLspRequest for PCEP Initiate message.
|
||||||
|
* Reference : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03.
|
||||||
|
*/
|
||||||
|
public class PcInitiatedLspRequestVer1 implements PcInitiatedLspRequest {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>)
|
||||||
|
<PCE-initiated-lsp-instantiation> ::= <SRP>
|
||||||
|
<LSP>
|
||||||
|
<END-POINTS>
|
||||||
|
<ERO>
|
||||||
|
[<attribute-list>]
|
||||||
|
<PCE-initiated-lsp-deletion> ::= <SRP>
|
||||||
|
<LSP>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcInitiatedLspRequestVer1.class);
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
private PcepSrpObject srpObject;
|
||||||
|
//PCEP LSP Object
|
||||||
|
private PcepLspObject lspObject;
|
||||||
|
//PCEP End Point Object
|
||||||
|
private PcepEndPointsObject endPointsObject;
|
||||||
|
//PCEP ERO Object
|
||||||
|
private PcepEroObject eroObject;
|
||||||
|
//PCEP Attribute list
|
||||||
|
private PcepAttribute pcepAttribute;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public PcInitiatedLspRequestVer1() {
|
||||||
|
srpObject = null;
|
||||||
|
lspObject = null;
|
||||||
|
endPointsObject = null;
|
||||||
|
eroObject = null;
|
||||||
|
pcepAttribute = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all parameters of PC initiated lsp request.
|
||||||
|
*
|
||||||
|
* @param srpObject PCEP srp Object
|
||||||
|
* @param lspObject PCEP lsp object
|
||||||
|
* @param endPointsObject PCPE endpoints object
|
||||||
|
* @param eroObject PCEP ero object
|
||||||
|
* @param pcepAttribute PCEP attribute
|
||||||
|
*/
|
||||||
|
public PcInitiatedLspRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject,
|
||||||
|
PcepEndPointsObject endPointsObject, PcepEroObject eroObject, PcepAttribute pcepAttribute) {
|
||||||
|
this.srpObject = srpObject;
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
this.endPointsObject = endPointsObject;
|
||||||
|
this.eroObject = eroObject;
|
||||||
|
this.pcepAttribute = pcepAttribute;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject getSrpObject() {
|
||||||
|
return srpObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject getLspObject() {
|
||||||
|
return lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEndPointsObject getEndPointsObject() {
|
||||||
|
return endPointsObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject getEroObject() {
|
||||||
|
return eroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute getPcepAttribute() {
|
||||||
|
return pcepAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSrpObject(PcepSrpObject srpobj) {
|
||||||
|
this.srpObject = srpobj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLspObject(PcepLspObject lspObject) {
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEndPointsObject(PcepEndPointsObject endPointsObject) {
|
||||||
|
this.endPointsObject = endPointsObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEroObject(PcepEroObject eroObject) {
|
||||||
|
this.eroObject = eroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPcepAttribute(PcepAttribute pcepAttribute) {
|
||||||
|
this.pcepAttribute = pcepAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PC initiated lsp reuqest.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcInitiatedLspRequest.Builder {
|
||||||
|
|
||||||
|
private boolean bIsSRPObjectSet = false;
|
||||||
|
private boolean bIsLSPObjectSet = false;
|
||||||
|
private boolean bIsEndPointsObjectSet = false;
|
||||||
|
private boolean bIsEROObjectSet = false;
|
||||||
|
private boolean bIsPcepAttributeSet = false;
|
||||||
|
private boolean bIsbRFlagSet = false;
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
private PcepSrpObject srpObject;
|
||||||
|
//PCEP LSP Object
|
||||||
|
private PcepLspObject lspObject;
|
||||||
|
//PCEP End Point Object
|
||||||
|
private PcepEndPointsObject endPointsObject;
|
||||||
|
//PCEP ERO Object
|
||||||
|
private PcepEroObject eroObject;
|
||||||
|
//PCEP Attribute list
|
||||||
|
private PcepAttribute pcepAttribute;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcInitiatedLspRequest build() throws PcepParseException {
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
PcepSrpObject srpObject = null;
|
||||||
|
//PCEP LSP Object
|
||||||
|
PcepLspObject lspObject = null;
|
||||||
|
//PCEP End Point Object
|
||||||
|
PcepEndPointsObject endPointsObject = null;
|
||||||
|
//PCEP ERO Object
|
||||||
|
PcepEroObject eroObject = null;
|
||||||
|
//PCEP Attribute list
|
||||||
|
PcepAttribute pcepAttribute = null;
|
||||||
|
boolean bRFlag = false;
|
||||||
|
|
||||||
|
if (!this.bIsSRPObjectSet) {
|
||||||
|
throw new PcepParseException("Srp object NOT Set while building PcInitiatedLspRequest");
|
||||||
|
} else {
|
||||||
|
srpObject = this.srpObject;
|
||||||
|
bRFlag = srpObject.getRFlag();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bRFlag) {
|
||||||
|
this.bIsbRFlagSet = true;
|
||||||
|
} else {
|
||||||
|
this.bIsbRFlagSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.bIsLSPObjectSet) {
|
||||||
|
throw new PcepParseException("LSP Object NOT Set while building PcInitiatedLspRequest");
|
||||||
|
} else {
|
||||||
|
lspObject = this.lspObject;
|
||||||
|
}
|
||||||
|
if (!this.bIsbRFlagSet) {
|
||||||
|
|
||||||
|
if (!this.bIsEndPointsObjectSet) {
|
||||||
|
throw new PcepParseException("EndPoints Object NOT Set while building PcInitiatedLspRequest");
|
||||||
|
} else {
|
||||||
|
endPointsObject = this.endPointsObject;
|
||||||
|
}
|
||||||
|
if (!this.bIsEROObjectSet) {
|
||||||
|
throw new PcepParseException("ERO Object NOT Set while building PcInitiatedLspRequest");
|
||||||
|
} else {
|
||||||
|
eroObject = this.eroObject;
|
||||||
|
}
|
||||||
|
if (bIsPcepAttributeSet) {
|
||||||
|
pcepAttribute = this.pcepAttribute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PcInitiatedLspRequestVer1(srpObject, lspObject, endPointsObject, eroObject, pcepAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject getSrpObject() {
|
||||||
|
return this.srpObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject getLspObject() {
|
||||||
|
return this.lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEndPointsObject getEndPointsObject() {
|
||||||
|
return this.endPointsObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject getEroObject() {
|
||||||
|
return this.eroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute getPcepAttribute() {
|
||||||
|
return this.pcepAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSrpObject(PcepSrpObject srpobj) {
|
||||||
|
this.srpObject = srpobj;
|
||||||
|
this.bIsSRPObjectSet = true;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLspObject(PcepLspObject lspObject) {
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
this.bIsLSPObjectSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setEndPointsObject(PcepEndPointsObject endPointsObject) {
|
||||||
|
this.endPointsObject = endPointsObject;
|
||||||
|
this.bIsEndPointsObjectSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setEroObject(PcepEroObject eroObject) {
|
||||||
|
this.eroObject = eroObject;
|
||||||
|
this.bIsEROObjectSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
|
||||||
|
this.pcepAttribute = pcepAttribute;
|
||||||
|
this.bIsPcepAttributeSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug(" PC-INITIATED LSP INITIATION REQUEST");
|
||||||
|
srpObject.print();
|
||||||
|
lspObject.print();
|
||||||
|
//if PC initiate then print end point and ero object [pcepattribute].
|
||||||
|
if (endPointsObject instanceof PcepEndPointsObject) {
|
||||||
|
endPointsObject.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eroObject instanceof PcepEroObject) {
|
||||||
|
eroObject.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pcepAttribute instanceof PcepAttribute) {
|
||||||
|
pcepAttribute.print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
|
||||||
|
toStrHelper
|
||||||
|
.add("SRP Object", srpObject)
|
||||||
|
.add("LSP object", lspObject);
|
||||||
|
|
||||||
|
if (endPointsObject instanceof PcepEndPointsObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("End Point Object", endPointsObject);
|
||||||
|
}
|
||||||
|
if (eroObject instanceof PcepEroObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("ERO Object", eroObject);
|
||||||
|
}
|
||||||
|
if (pcepAttribute instanceof PcepAttribute) {
|
||||||
|
toStrHelper
|
||||||
|
.add("Pcep Attribute", pcepAttribute);
|
||||||
|
}
|
||||||
|
return toStrHelper.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,469 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provides PCEP Attribute List.
|
||||||
|
*/
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepAttribute;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepIroObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspaObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMetricObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||||
|
|
||||||
|
/* Reference : RFC5440
|
||||||
|
* where:
|
||||||
|
* <attribute-list> ::=[<LSPA>]
|
||||||
|
* [<BANDWIDTH>]
|
||||||
|
* [<metric-list>]
|
||||||
|
* [<IRO>]
|
||||||
|
*
|
||||||
|
* <metric-list> ::=<METRIC>[<metric-list>]
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PcepAttributeVer1 implements PcepAttribute {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepAttributeVer1.class);
|
||||||
|
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
//PCEP LSPA Object
|
||||||
|
private PcepLspaObject lspaObject;
|
||||||
|
private boolean isLspaObjectSet;
|
||||||
|
|
||||||
|
//PCEP Bandwidth Object
|
||||||
|
private PcepBandwidthObject bandwidthObject;
|
||||||
|
private boolean isBandwidthObjectSet;
|
||||||
|
|
||||||
|
//PCEP Metric list
|
||||||
|
private LinkedList<PcepMetricObject> llMetricList;
|
||||||
|
private boolean isMetricListSet;
|
||||||
|
|
||||||
|
//PCEP IRO object
|
||||||
|
private PcepIroObject iroObject;
|
||||||
|
private boolean isIroObjectSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor to initialize member variables.
|
||||||
|
*/
|
||||||
|
public PcepAttributeVer1() {
|
||||||
|
|
||||||
|
lspaObject = null;
|
||||||
|
bandwidthObject = null;
|
||||||
|
llMetricList = null;
|
||||||
|
iroObject = null;
|
||||||
|
this.isLspaObjectSet = false;
|
||||||
|
this.isBandwidthObjectSet = false;
|
||||||
|
this.isMetricListSet = false;
|
||||||
|
this.isIroObjectSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all parameters for PCEP attribute.
|
||||||
|
*
|
||||||
|
* @param lspaObject PCEP lspa Object.
|
||||||
|
* @param bandwidthObject PCEP bandwidth object.
|
||||||
|
* @param llMetricList list of PCEP metric objects.
|
||||||
|
* @param iroObject PCEP iro object.
|
||||||
|
*/
|
||||||
|
public PcepAttributeVer1(PcepLspaObject lspaObject, PcepBandwidthObject bandwidthObject,
|
||||||
|
LinkedList<PcepMetricObject> llMetricList, PcepIroObject iroObject) {
|
||||||
|
|
||||||
|
this.lspaObject = lspaObject;
|
||||||
|
this.bandwidthObject = bandwidthObject;
|
||||||
|
this.llMetricList = llMetricList;
|
||||||
|
this.iroObject = iroObject;
|
||||||
|
if (lspaObject == null) {
|
||||||
|
this.isLspaObjectSet = false;
|
||||||
|
} else {
|
||||||
|
this.isLspaObjectSet = true;
|
||||||
|
}
|
||||||
|
if (bandwidthObject == null) {
|
||||||
|
this.isBandwidthObjectSet = false;
|
||||||
|
} else {
|
||||||
|
this.isBandwidthObjectSet = true;
|
||||||
|
}
|
||||||
|
if (llMetricList == null) {
|
||||||
|
this.isMetricListSet = false;
|
||||||
|
} else {
|
||||||
|
this.isMetricListSet = true;
|
||||||
|
}
|
||||||
|
if (iroObject == null) {
|
||||||
|
this.isIroObjectSet = false;
|
||||||
|
} else {
|
||||||
|
this.isIroObjectSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize bandwidthObject.
|
||||||
|
*
|
||||||
|
* @param bandwidthObject bandwidth object
|
||||||
|
*/
|
||||||
|
public PcepAttributeVer1(PcepBandwidthObject bandwidthObject) {
|
||||||
|
this.isLspaObjectSet = false;
|
||||||
|
|
||||||
|
this.bandwidthObject = bandwidthObject;
|
||||||
|
this.isBandwidthObjectSet = true;
|
||||||
|
|
||||||
|
this.isMetricListSet = false;
|
||||||
|
|
||||||
|
this.isIroObjectSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse list for MeticObject.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return true if parsing metric list is success
|
||||||
|
* @throws PcepParseException when a non metric object is received
|
||||||
|
*/
|
||||||
|
public boolean parseMetricList(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (null == llMetricList) {
|
||||||
|
llMetricList = new LinkedList<PcepMetricObject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
PcepMetricObject metriclist;
|
||||||
|
|
||||||
|
//caller should verify for metric object
|
||||||
|
byte yObjClass = PcepMetricObjectVer1.METRIC_OBJ_CLASS;
|
||||||
|
byte yObjType = PcepMetricObjectVer1.METRIC_OBJ_TYPE;
|
||||||
|
|
||||||
|
while ((yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS)
|
||||||
|
&& (yObjType == PcepMetricObjectVer1.METRIC_OBJ_TYPE)) {
|
||||||
|
|
||||||
|
metriclist = PcepMetricObjectVer1.read(cb);
|
||||||
|
llMetricList.add(metriclist);
|
||||||
|
yObjClass = 0;
|
||||||
|
yObjType = 0;
|
||||||
|
|
||||||
|
if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
|
||||||
|
cb.markReaderIndex();
|
||||||
|
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
cb.resetReaderIndex();
|
||||||
|
yObjClass = tempObjHeader.getObjClass();
|
||||||
|
yObjType = tempObjHeader.getObjType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads lspa , bandwidth , Metriclist and Iro objects and sets the objects.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return instance of Pcep Attribute
|
||||||
|
* @throws PcepParseException while parsing Pcep Attributes from channel buffer
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static PcepAttribute read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//check whether any pcep attribute is present
|
||||||
|
cb.markReaderIndex();
|
||||||
|
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
cb.resetReaderIndex();
|
||||||
|
byte yObjClass = tempObjHeader.getObjClass();
|
||||||
|
|
||||||
|
if (PcepLspaObjectVer1.LSPA_OBJ_CLASS != yObjClass && PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS != yObjClass
|
||||||
|
&& PcepMetricObjectVer1.METRIC_OBJ_CLASS != yObjClass && PcepIroObjectVer1.IRO_OBJ_CLASS != yObjClass) {
|
||||||
|
//No PCEP attribute is present
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PcepAttributeVer1 pcepAttribute = new PcepAttributeVer1();
|
||||||
|
|
||||||
|
//If LSPA present then store it.LSPA is optional
|
||||||
|
if (yObjClass == PcepLspaObjectVer1.LSPA_OBJ_CLASS) {
|
||||||
|
pcepAttribute.setLspaObject(PcepLspaObjectVer1.read(cb));
|
||||||
|
yObjClass = checkNextObject(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If BANDWIDTH present then store it.BANDWIDTH is optional
|
||||||
|
if (yObjClass == PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS) {
|
||||||
|
pcepAttribute.setBandwidthObject(PcepBandwidthObjectVer1.read(cb));
|
||||||
|
yObjClass = checkNextObject(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If Metric list present then store it.MetricList is optional
|
||||||
|
if (yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS) {
|
||||||
|
pcepAttribute.parseMetricList(cb);
|
||||||
|
yObjClass = checkNextObject(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If IRO present then store it.IRO is optional
|
||||||
|
if (yObjClass == PcepIroObjectVer1.IRO_OBJ_CLASS) {
|
||||||
|
pcepAttribute.setIroObject(PcepIroObjectVer1.read(cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
PcepLspaObject lspaObject = pcepAttribute.getLspaObject();
|
||||||
|
PcepBandwidthObject bandwidthObject = pcepAttribute.getBandwidthObject();
|
||||||
|
LinkedList<PcepMetricObject> metriclist = pcepAttribute.llMetricList;
|
||||||
|
PcepIroObject iroObject = pcepAttribute.getIroObject();
|
||||||
|
|
||||||
|
return new PcepAttributeVer1(lspaObject, bandwidthObject, metriclist, iroObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether there is a more object or not.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return instance of object header
|
||||||
|
*/
|
||||||
|
private static byte checkNextObject(ChannelBuffer cb) {
|
||||||
|
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cb.markReaderIndex();
|
||||||
|
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
cb.resetReaderIndex();
|
||||||
|
return tempObjHeader.getObjClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
int iLenStartIndex = cb.writerIndex();
|
||||||
|
//PCEP LSPA object is optional
|
||||||
|
if (this.isLspaObjectSet) {
|
||||||
|
this.lspaObject.write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//PCEP BANDWIDTH object is optional
|
||||||
|
if (this.isBandwidthObjectSet) {
|
||||||
|
this.bandwidthObject.write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//PCEP Metric list is optional
|
||||||
|
if (this.isMetricListSet) {
|
||||||
|
ListIterator<PcepMetricObject> listIterator = this.llMetricList.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().write(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//PCEP IRO object is optional
|
||||||
|
if (this.isIroObjectSet) {
|
||||||
|
this.iroObject.write(cb);
|
||||||
|
}
|
||||||
|
return cb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspaObject getLspaObject() {
|
||||||
|
return lspaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepBandwidthObject getBandwidthObject() {
|
||||||
|
return bandwidthObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepMetricObject> getMetricObjectList() {
|
||||||
|
return llMetricList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepIroObject getIroObject() {
|
||||||
|
return iroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBandwidthObject(PcepBandwidthObject bandwidthObject) {
|
||||||
|
this.isBandwidthObjectSet = true;
|
||||||
|
this.bandwidthObject = bandwidthObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) {
|
||||||
|
this.isMetricListSet = true;
|
||||||
|
this.llMetricList = llMetricList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLspaObject(PcepLspaObject lspaObject) {
|
||||||
|
this.isLspaObjectSet = true;
|
||||||
|
this.lspaObject = lspaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIroObject(PcepIroObject iroObject) {
|
||||||
|
this.isIroObjectSet = true;
|
||||||
|
this.iroObject = iroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP attributes.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepAttribute.Builder {
|
||||||
|
|
||||||
|
//PCEP LSPA Object
|
||||||
|
private PcepLspaObject lspaObject;
|
||||||
|
private boolean isLspaObjectSet;
|
||||||
|
|
||||||
|
//PCEP BANDWIDTH Object
|
||||||
|
private PcepBandwidthObject bandwidthObject;
|
||||||
|
private boolean isBandwidthObjectSet;
|
||||||
|
|
||||||
|
//PCEP Metric list
|
||||||
|
private LinkedList<PcepMetricObject> llMetricList;
|
||||||
|
private boolean isMetricListSet;
|
||||||
|
|
||||||
|
//PCEP IRO object
|
||||||
|
private PcepIroObject iroObject;
|
||||||
|
private boolean isIroObjectSet;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute build() {
|
||||||
|
|
||||||
|
//PCEP LSPA Object
|
||||||
|
PcepLspaObject lspaObject = null;
|
||||||
|
|
||||||
|
//PCEP BANDWIDTH Object
|
||||||
|
PcepBandwidthObject bandwidthObject = null;
|
||||||
|
|
||||||
|
//PCEP Metric list
|
||||||
|
LinkedList<PcepMetricObject> llMetricList = null;
|
||||||
|
|
||||||
|
//PCEP IRO object
|
||||||
|
PcepIroObject iroObject = null;
|
||||||
|
|
||||||
|
if (this.isLspaObjectSet) {
|
||||||
|
lspaObject = this.lspaObject;
|
||||||
|
}
|
||||||
|
if (this.isBandwidthObjectSet) {
|
||||||
|
bandwidthObject = this.bandwidthObject;
|
||||||
|
}
|
||||||
|
if (this.isMetricListSet) {
|
||||||
|
llMetricList = this.llMetricList;
|
||||||
|
}
|
||||||
|
if (this.isIroObjectSet) {
|
||||||
|
iroObject = this.iroObject;
|
||||||
|
}
|
||||||
|
return new PcepAttributeVer1(lspaObject, bandwidthObject, llMetricList, iroObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspaObject getLspaObject() {
|
||||||
|
return this.lspaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepBandwidthObject getBandwidthObject() {
|
||||||
|
return this.bandwidthObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepMetricObject> getMetricObjectList() {
|
||||||
|
return this.llMetricList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepIroObject getIroObject() {
|
||||||
|
return this.iroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setBandwidthObject(PcepBandwidthObject bandwidthObject) {
|
||||||
|
this.isBandwidthObjectSet = true;
|
||||||
|
this.bandwidthObject = bandwidthObject;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) {
|
||||||
|
this.isMetricListSet = true;
|
||||||
|
this.llMetricList = llMetricList;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLspaObject(PcepLspaObject lspaObject) {
|
||||||
|
this.isLspaObjectSet = true;
|
||||||
|
this.lspaObject = lspaObject;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIroObject(PcepIroObject iroObject) {
|
||||||
|
this.isIroObjectSet = true;
|
||||||
|
this.iroObject = iroObject;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("ATTRIBUTE LIST");
|
||||||
|
if (lspaObject instanceof PcepLspaObject) {
|
||||||
|
lspaObject.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bandwidthObject instanceof PcepBandwidthObject) {
|
||||||
|
bandwidthObject.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (llMetricList != null) {
|
||||||
|
log.debug("METRIC LIST");
|
||||||
|
ListIterator<PcepMetricObject> listIterator = llMetricList.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iroObject instanceof PcepIroObject) {
|
||||||
|
iroObject.print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
|
||||||
|
|
||||||
|
if (lspaObject instanceof PcepLspaObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("PCEP lspa Object", lspaObject);
|
||||||
|
}
|
||||||
|
if (bandwidthObject instanceof PcepBandwidthObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("bandwidth Object", bandwidthObject);
|
||||||
|
}
|
||||||
|
if (llMetricList instanceof PcepMetricObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("Pcep Metric object List", llMetricList);
|
||||||
|
}
|
||||||
|
if (iroObject instanceof PcepIroObject) {
|
||||||
|
toStrHelper
|
||||||
|
.add("iro Object", iroObject);
|
||||||
|
}
|
||||||
|
return toStrHelper.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,242 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides PcepBandwidthObject.
|
||||||
|
*/
|
||||||
|
public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RFC : 5440 , section : 7.7.
|
||||||
|
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 |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
The BANDWIDTH Object format
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepBandwidthObjectVer1.class);
|
||||||
|
/*
|
||||||
|
* Requested bandwidth: BANDWIDTH Object-Type is 1.
|
||||||
|
Bandwidth of an existing TE LSP for which a re-optimization is
|
||||||
|
requested. BANDWIDTH Object-Type is 2.
|
||||||
|
*/
|
||||||
|
//Right now handling type 1
|
||||||
|
public static final byte BANDWIDTH_OBJ_TYPE = 1;
|
||||||
|
public static final byte BANDWIDTH_OBJ_CLASS = 5;
|
||||||
|
public static final byte BANDWIDTH_OBJECT_VERSION = 1;
|
||||||
|
public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS,
|
||||||
|
BANDWIDTH_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
|
||||||
|
BANDWIDTH_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader bandwidthObjHeader;
|
||||||
|
private int iBandwidth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to bandwidth object header and bandwidth.
|
||||||
|
*
|
||||||
|
* @param bandwidthObjHeader bandwidth object header
|
||||||
|
* @param iBandwidth bandwidth value
|
||||||
|
*/
|
||||||
|
public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) {
|
||||||
|
this.bandwidthObjHeader = bandwidthObjHeader;
|
||||||
|
this.iBandwidth = iBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize bandwidth.
|
||||||
|
*
|
||||||
|
* @param iBandwidth bandwidth value
|
||||||
|
*/
|
||||||
|
public PcepBandwidthObjectVer1(int iBandwidth) {
|
||||||
|
this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER;
|
||||||
|
this.iBandwidth = iBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Object Header.
|
||||||
|
*
|
||||||
|
* @return bandwidthObjHeader
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getBandwidthObjHeader() {
|
||||||
|
return this.bandwidthObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Object Header.
|
||||||
|
*
|
||||||
|
* @param obj bandwidth object header
|
||||||
|
*/
|
||||||
|
public void setBandwidthObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.bandwidthObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBandwidth() {
|
||||||
|
return this.iBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBandwidth(int iBandwidth) {
|
||||||
|
this.iBandwidth = iBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns object of PcepBandwidthObject.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer to parse
|
||||||
|
* @return object of PcepBandwidthObject
|
||||||
|
* @throws PcepParseException while parsing channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader bandwidthObjHeader;
|
||||||
|
int iBandwidth;
|
||||||
|
|
||||||
|
bandwidthObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
iBandwidth = cb.readInt();
|
||||||
|
|
||||||
|
return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
int objLenIndex = bandwidthObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb.writeInt(iBandwidth);
|
||||||
|
short hLength = (short) (cb.writerIndex() - objStartIndex);
|
||||||
|
cb.setShort(objLenIndex, hLength);
|
||||||
|
//will be helpful during print().
|
||||||
|
bandwidthObjHeader.setObjLen(hLength);
|
||||||
|
|
||||||
|
return cb.writerIndex() - objStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builder class for PCEP bandwidth object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepBandwidthObject.Builder {
|
||||||
|
|
||||||
|
private PcepObjectHeader bandwidthObjHeader;
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
|
||||||
|
private int iBandwidth;
|
||||||
|
private boolean bIsBandwidthSet = false;
|
||||||
|
|
||||||
|
private boolean bPFlag;
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
|
||||||
|
private boolean bIFlag;
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepBandwidthObject build() throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader bandwidthObjHeader = this.bIsHeaderSet ? this.bandwidthObjHeader
|
||||||
|
: DEFAULT_BANDWIDTH_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
bandwidthObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
bandwidthObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.bIsBandwidthSet) {
|
||||||
|
throw new PcepParseException("bandwidth not Set while building Bandwidth Object.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBandwidth() {
|
||||||
|
return this.iBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getBandwidthObjHeader() {
|
||||||
|
return this.bandwidthObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setBandwidthObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.bandwidthObjHeader = obj;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setBandwidth(int iBandwidth) {
|
||||||
|
this.iBandwidth = iBandwidth;
|
||||||
|
this.bIsBandwidthSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("BANDWIDTH OBJECT");
|
||||||
|
bandwidthObjHeader.print();
|
||||||
|
log.debug("Bandwidth: " + iBandwidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("bandwidth Object Header", bandwidthObjHeader)
|
||||||
|
.add("Bandwidth", iBandwidth)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,356 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepCloseMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageWriter;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepType;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RFC : 5440 , section : 6.8
|
||||||
|
* <Close Message> ::= <Common Header> <CLOSE>
|
||||||
|
*
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Ver | Flags | Message-Type | Message-Length |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Object-Class | OT |Res|P|I| Object Length (bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Reserved | Flags | Reason |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
// Optional TLVs //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
class PcepCloseMsgVer1 implements PcepCloseMsg {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepCloseMsgVer1.class);
|
||||||
|
|
||||||
|
// Pcep version: 1
|
||||||
|
public static final byte PACKET_VERSION = 1;
|
||||||
|
public static final int PACKET_MINIMUM_LENGTH = 12;
|
||||||
|
public static final PcepType MSG_TYPE = PcepType.CLOSE;
|
||||||
|
public static final byte CLOSE_OBJ_TYPE = 1;
|
||||||
|
public static final byte CLOSE_OBJ_CLASS = 15;
|
||||||
|
public static final byte CLOSE_OBJECT_VERSION = 1;
|
||||||
|
public static final byte DEFAULT_REASON = 1; // Default reason to close
|
||||||
|
public static final short CLOSE_OBJ_MINIMUM_LENGTH = 8;
|
||||||
|
public static final int SHIFT_FLAG = 5;
|
||||||
|
static final PcepObjectHeader DEFAULT_CLOSE_HEADER = new PcepObjectHeader(CLOSE_OBJ_CLASS, CLOSE_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, CLOSE_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private final PcepObjectHeader closeObjHeader;
|
||||||
|
private byte yReason;
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
|
||||||
|
public static final PcepCloseMsgVer1.Reader READER = new Reader();
|
||||||
|
|
||||||
|
static class Reader implements PcepMessageReader<PcepCloseMsg> {
|
||||||
|
PcepObjectHeader closeObjHeader;
|
||||||
|
byte yReason;
|
||||||
|
// Optional TLV
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepCloseMsg readFrom(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Packet size is less than the minimum length.");
|
||||||
|
}
|
||||||
|
// fixed value property version == 1
|
||||||
|
byte version = cb.readByte();
|
||||||
|
version = (byte) (version >> SHIFT_FLAG);
|
||||||
|
if (version != PACKET_VERSION) {
|
||||||
|
throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version);
|
||||||
|
}
|
||||||
|
// fixed value property type == 7
|
||||||
|
byte type = cb.readByte();
|
||||||
|
if (type != MSG_TYPE.getType()) {
|
||||||
|
throw new PcepParseException("Wrong type. Expected=PcepType.CLOSE(7), got=" + type);
|
||||||
|
}
|
||||||
|
short length = cb.readShort();
|
||||||
|
if (length < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
|
||||||
|
+ length);
|
||||||
|
}
|
||||||
|
closeObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
// Reserved
|
||||||
|
cb.readShort();
|
||||||
|
// Flags
|
||||||
|
cb.readByte();
|
||||||
|
// Reason
|
||||||
|
yReason = cb.readByte();
|
||||||
|
// parse optional TLV
|
||||||
|
llOptionalTlv = parseOptionalTlv(cb);
|
||||||
|
return new PcepCloseMsgVer1(closeObjHeader, yReason, llOptionalTlv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the list of Optional Tlvs.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return list of Optional Tlvs
|
||||||
|
* @throws PcepParseException when fails to parse optional tlvs
|
||||||
|
*/
|
||||||
|
public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
/*
|
||||||
|
rfc 5440:
|
||||||
|
Optional TLVs may be included within the CLOSE object body. The
|
||||||
|
specification of such TLVs is outside the scope of this document.
|
||||||
|
*/
|
||||||
|
return llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize PCEP close Message with all the parameters.
|
||||||
|
*
|
||||||
|
* @param closeObjHeader object header for close message
|
||||||
|
* @param yReason reason for closing the channel
|
||||||
|
* @param llOptionalTlv list of optional tlvs
|
||||||
|
*/
|
||||||
|
PcepCloseMsgVer1(PcepObjectHeader closeObjHeader, byte yReason, LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
|
||||||
|
this.closeObjHeader = closeObjHeader;
|
||||||
|
this.yReason = yReason;
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP close message.
|
||||||
|
*/
|
||||||
|
static class Builder implements PcepCloseMsg.Builder {
|
||||||
|
|
||||||
|
// PCEP Close message fields
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
private PcepObjectHeader closeObjHeader;
|
||||||
|
private boolean bIsReasonSet = false;
|
||||||
|
private byte yReason;
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return PcepType.CLOSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepCloseMsg build() {
|
||||||
|
|
||||||
|
PcepObjectHeader closeObjHeader = this.bIsHeaderSet ? this.closeObjHeader : DEFAULT_CLOSE_HEADER;
|
||||||
|
byte yReason = this.bIsReasonSet ? this.yReason : DEFAULT_REASON;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
closeObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
closeObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
return new PcepCloseMsgVer1(closeObjHeader, yReason, this.llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getCloseObjHeader() {
|
||||||
|
return this.closeObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setCloseObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.closeObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getReason() {
|
||||||
|
return this.yReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setReason(byte value) {
|
||||||
|
this.yReason = value;
|
||||||
|
this.bIsReasonSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
WRITER.write(cb, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Writer WRITER = new Writer();
|
||||||
|
|
||||||
|
static class Writer implements PcepMessageWriter<PcepCloseMsgVer1> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ChannelBuffer cb, PcepCloseMsgVer1 message) throws PcepParseException {
|
||||||
|
int startIndex = cb.writerIndex();
|
||||||
|
// first 3 bits set to version
|
||||||
|
cb.writeByte((byte) (PACKET_VERSION << SHIFT_FLAG));
|
||||||
|
// message type
|
||||||
|
cb.writeByte(MSG_TYPE.getType());
|
||||||
|
// length is length of variable message, will be updated at the end
|
||||||
|
// Store the position of message
|
||||||
|
// length in buffer
|
||||||
|
int msgLenIndex = cb.writerIndex();
|
||||||
|
cb.writeShort((short) 0);
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
int objLenIndex = message.closeObjHeader.write(cb);
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Failed to write Close object header.");
|
||||||
|
}
|
||||||
|
// first 3 bits set to version
|
||||||
|
cb.writeShort(0); // Reserved
|
||||||
|
cb.writeByte(0); // Flags
|
||||||
|
cb.writeByte(message.yReason);
|
||||||
|
// Pack optional TLV
|
||||||
|
packOptionalTlv(cb, message);
|
||||||
|
int length = cb.writerIndex() - objStartIndex;
|
||||||
|
cb.setShort(objLenIndex, (short) length);
|
||||||
|
// will be helpful during print().
|
||||||
|
message.closeObjHeader.setObjLen((short) length);
|
||||||
|
// As per RFC the length of object should be
|
||||||
|
// multiples of 4
|
||||||
|
int pad = length % 4;
|
||||||
|
if (pad != 0) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; i++) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
length = length + pad;
|
||||||
|
}
|
||||||
|
// update message length field
|
||||||
|
length = cb.writerIndex() - startIndex;
|
||||||
|
cb.setShort(msgLenIndex, (short) length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packOptionalTlv(ChannelBuffer cb, PcepCloseMsgVer1 message) {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = message.llOptionalTlv;
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().write(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return MSG_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getReason() {
|
||||||
|
return this.yReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReason(byte value) {
|
||||||
|
this.yReason = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("CLOSE MESSAGE");
|
||||||
|
closeObjHeader.print();
|
||||||
|
int x = yReason & 0xFF;
|
||||||
|
log.debug("Reason: " + x);
|
||||||
|
log.debug("OPTINAL TLV:");
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("close Object Header", closeObjHeader)
|
||||||
|
.add("Reason", yReason)
|
||||||
|
.add("Optional Tlv list", llOptionalTlv)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,268 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEndPointsObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepEndPointsObjectVer1 implements PcepEndPointsObject {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RFC : 5440 , section : 7.6
|
||||||
|
* An End point is defined as follows:
|
||||||
|
END-POINTS Object-Class is 4.
|
||||||
|
|
||||||
|
END-POINTS Object-Type is 1 for IPv4 and 2 for IPv6.
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Object-Class | OT |Res|P|I| Object Length (bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Source IPv4 address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Destination IPv4 address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepEndPointsObjectVer1.class);
|
||||||
|
|
||||||
|
static final byte END_POINTS_OBJ_TYPE = 1;
|
||||||
|
static final byte END_POINTS_OBJ_CLASS = 4;
|
||||||
|
static final byte END_POINTS_OBJECT_VERSION = 1;
|
||||||
|
static final short END_POINTS_OBJ_MINIMUM_LENGTH = 12;
|
||||||
|
public static byte endPointObjType;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_END_POINTS_OBJECT_HEADER = new PcepObjectHeader(END_POINTS_OBJ_CLASS,
|
||||||
|
END_POINTS_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
|
||||||
|
END_POINTS_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader endPointsObjHeader;
|
||||||
|
public int sourceIpAddress;
|
||||||
|
public int destIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all variables.
|
||||||
|
*
|
||||||
|
* @param endPointsObjHeader end points object header
|
||||||
|
* @param sourceIpAddress source IP address
|
||||||
|
* @param destIpAddress destination IP address
|
||||||
|
*/
|
||||||
|
public PcepEndPointsObjectVer1(PcepObjectHeader endPointsObjHeader, int sourceIpAddress, int destIpAddress) {
|
||||||
|
|
||||||
|
this.endPointsObjHeader = endPointsObjHeader;
|
||||||
|
this.sourceIpAddress = sourceIpAddress;
|
||||||
|
this.destIpAddress = destIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets End Points Object Header.
|
||||||
|
*
|
||||||
|
* @param obj of PcepObjectHeader
|
||||||
|
*/
|
||||||
|
public void setEndPointsObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.endPointsObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSourceIpAddress(int sourceIpAddress) {
|
||||||
|
this.sourceIpAddress = sourceIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDestIpAddress(int destIpAddress) {
|
||||||
|
this.destIpAddress = destIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceIpAddress() {
|
||||||
|
return this.sourceIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDestIpAddress() {
|
||||||
|
return this.destIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns object of PcepEndPointsObject.
|
||||||
|
*
|
||||||
|
* @param cb of channel buffer
|
||||||
|
* @return object of PcepEndPointsObject
|
||||||
|
* @throws PcepParseException while parsing channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepEndPointsObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader endPointsObjHeader;
|
||||||
|
int sourceIpAddress;
|
||||||
|
int destIpAddress;
|
||||||
|
|
||||||
|
endPointsObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
if (END_POINTS_OBJ_TYPE == endPointsObjHeader.getObjType()
|
||||||
|
&& END_POINTS_OBJ_CLASS == endPointsObjHeader.getObjClass()) {
|
||||||
|
sourceIpAddress = cb.readInt();
|
||||||
|
destIpAddress = cb.readInt();
|
||||||
|
} else {
|
||||||
|
throw new PcepParseException("Expected PcepEndPointsObject.");
|
||||||
|
}
|
||||||
|
return new PcepEndPointsObjectVer1(endPointsObjHeader, sourceIpAddress, destIpAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
//write common header
|
||||||
|
int objLenIndex = endPointsObjHeader.write(cb);
|
||||||
|
|
||||||
|
//write source IPv4 IP
|
||||||
|
cb.writeInt(sourceIpAddress);
|
||||||
|
//write destination IPv4 IP
|
||||||
|
cb.writeInt(destIpAddress);
|
||||||
|
|
||||||
|
int length = cb.writerIndex() - objStartIndex;
|
||||||
|
//now write EndPoints Object Length
|
||||||
|
cb.setShort(objLenIndex, (short) length);
|
||||||
|
//will be helpful during print().
|
||||||
|
endPointsObjHeader.setObjLen((short) length);
|
||||||
|
|
||||||
|
return cb.writerIndex();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP end points objects.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepEndPointsObject.Builder {
|
||||||
|
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
private boolean bIsSourceIpAddressset = false;
|
||||||
|
private boolean bIsDestIpAddressset = false;
|
||||||
|
private PcepObjectHeader endpointsObjHeader;
|
||||||
|
private int sourceIpAddress;
|
||||||
|
private int destIpAddress;
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEndPointsObject build() throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader endpointsObjHeader = this.bIsHeaderSet ? this.endpointsObjHeader
|
||||||
|
: DEFAULT_END_POINTS_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
endpointsObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
endpointsObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.bIsSourceIpAddressset) {
|
||||||
|
throw new PcepParseException("SourceIpAddress not set while building EndPoints object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.bIsDestIpAddressset) {
|
||||||
|
throw new PcepParseException("DestIpAddress not set while building EndPoints object");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepEndPointsObjectVer1(endpointsObjHeader, this.sourceIpAddress, this.destIpAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getEndPointsObjHeader() {
|
||||||
|
return this.endpointsObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setEndPointsObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.endpointsObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceIpAddress() {
|
||||||
|
return this.sourceIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSourceIpAddress(int sourceIpAddress) {
|
||||||
|
this.sourceIpAddress = sourceIpAddress;
|
||||||
|
this.bIsSourceIpAddressset = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDestIpAddress() {
|
||||||
|
return this.destIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setDestIpAddress(int destIpAddress) {
|
||||||
|
this.destIpAddress = destIpAddress;
|
||||||
|
this.bIsDestIpAddressset = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("ENDPOINT OBJECT");
|
||||||
|
long lTemp;
|
||||||
|
lTemp = sourceIpAddress & 0xFFFFFFFF;
|
||||||
|
String str = "Source IP Address: " + lTemp;
|
||||||
|
log.debug(str);
|
||||||
|
lTemp = destIpAddress & 0xFFFFFFFF;
|
||||||
|
str = "destination IP Address: " + lTemp;
|
||||||
|
log.debug(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("sourceIpAddress", sourceIpAddress)
|
||||||
|
.add("destIpAddress", destIpAddress)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,418 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEroObject;
|
||||||
|
import org.onosproject.pcepio.types.AutonomousSystemTlv;
|
||||||
|
import org.onosproject.pcepio.types.IPv4SubObject;
|
||||||
|
import org.onosproject.pcepio.types.IPv6SubObject;
|
||||||
|
import org.onosproject.pcepio.types.PathKeySubObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.onosproject.pcepio.types.SrEroSubObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rfc3209
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Object-Class | OT |Res|P|I| Object Length (bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
// (Subobjects) //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
If a Path message contains multiple EXPLICIT_ROUTE objects, only the
|
||||||
|
first object is meaningful. Subsequent EXPLICIT_ROUTE objects MAY be
|
||||||
|
ignored and SHOULD NOT be propagated.
|
||||||
|
|
||||||
|
In current implementation, only strict hops are supported. So,
|
||||||
|
empty ERO with no sub-objects is considered illegal.
|
||||||
|
|
||||||
|
Subobjects:
|
||||||
|
0 1
|
||||||
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+
|
||||||
|
|L| Type | Length | (Subobject contents) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+
|
||||||
|
|
||||||
|
L
|
||||||
|
|
||||||
|
The L bit is an attribute of the subobject. The L bit is set
|
||||||
|
if the subobject represents a loose hop in the explicit route.
|
||||||
|
If the bit is not set, the subobject represents a strict hop in
|
||||||
|
the explicit route.
|
||||||
|
|
||||||
|
Type
|
||||||
|
|
||||||
|
The Type indicates the type of contents of the subobject.
|
||||||
|
|
||||||
|
|
||||||
|
Subobject 1: IPv4 address
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | IPv4 address (4 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv4 address (continued) | Prefix Length | Resvd |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
Subobject 2: IPv6 Prefix
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | IPv6 address (16 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) | Prefix Length | Resvd |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
Subobject 3: Autonomous System Number
|
||||||
|
|
||||||
|
The contents of an Autonomous System (AS) number subobject are a 2-
|
||||||
|
octet AS number. The abstract node represented by this subobject is
|
||||||
|
the set of nodes belonging to the autonomous system.
|
||||||
|
|
||||||
|
The length of the AS number subobject is 4 octets.
|
||||||
|
|
||||||
|
Subobject 4: PATH_KEY_32_BIT_SUB_OBJ_TYPE:
|
||||||
|
|
||||||
|
Pathkey subobject(RFC 5520):
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | Path-Key |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| PCE ID (4 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
Subobject 5: SR_ERO_SUB_OBJ_TYPE:
|
||||||
|
|
||||||
|
SR-ERO subobject: (draft-ietf-pce-segment-routing-00)
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | ST | Flags |F|S|C|M|
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| SID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// NAI (variable) //
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
public class PcepEroObjectVer1 implements PcepEroObject {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepEroObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte ERO_OBJ_TYPE = 1;
|
||||||
|
public static final byte ERO_OBJ_CLASS = 7;
|
||||||
|
public static final byte ERO_OBJECT_VERSION = 1;
|
||||||
|
public static final short ERO_OBJ_MINIMUM_LENGTH = 12;
|
||||||
|
public static final byte IPV4_TYPE = 1;
|
||||||
|
public static final byte PATH_KEY_32_BIT_SUB_OBJ_TYPE = 64;
|
||||||
|
public static final int LABEL_SUB_OBJ_TYPE = 3;
|
||||||
|
public static final int SR_ERO_SUB_OBJ_TYPE = 96;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
public static final int YTYPE_SHIFT_VALUE = 0x7F;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_ERO_OBJECT_HEADER = new PcepObjectHeader(ERO_OBJ_CLASS, ERO_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, ERO_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader eroObjHeader;
|
||||||
|
private LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reset variables.
|
||||||
|
*/
|
||||||
|
public PcepEroObjectVer1() {
|
||||||
|
this.eroObjHeader = null;
|
||||||
|
this.llSubObjects = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize parameters of ERO object.
|
||||||
|
*
|
||||||
|
* @param eroObjHeader ERO object header
|
||||||
|
* @param llSubObjects list of sub objects.
|
||||||
|
*/
|
||||||
|
public PcepEroObjectVer1(PcepObjectHeader eroObjHeader, LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
|
||||||
|
this.eroObjHeader = eroObjHeader;
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ERO object header.
|
||||||
|
*
|
||||||
|
* @return eroObjHeader ERO object header
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getEroObjHeader() {
|
||||||
|
return this.eroObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Object Header.
|
||||||
|
*
|
||||||
|
* @param obj ERO object header
|
||||||
|
*/
|
||||||
|
public void setEroObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.eroObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getSubObjects() {
|
||||||
|
return this.llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSubObjects(LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns object of PcepEroObject.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer.
|
||||||
|
* @return object of PcepEroObject
|
||||||
|
* @throws PcepParseException when ERO object is not present in channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepEroObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader eroObjHeader;
|
||||||
|
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
eroObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
if (eroObjHeader.getObjClass() != PcepEroObjectVer1.ERO_OBJ_CLASS) {
|
||||||
|
log.debug("ErrorType:" + PcepErrorDetailInfo.ERROR_TYPE_6 + " ErrorValue:"
|
||||||
|
+ PcepErrorDetailInfo.ERROR_VALUE_9);
|
||||||
|
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eroObjHeader.getObjLen() > OBJECT_HEADER_LENGTH) {
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(eroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
|
||||||
|
llSubObjects = parseSubObjects(tempCb);
|
||||||
|
}
|
||||||
|
return new PcepEroObjectVer1(eroObjHeader, llSubObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse list of Sub Objects.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return list of Sub Objects
|
||||||
|
* @throws PcepParseException when fails to parse sub object list
|
||||||
|
*/
|
||||||
|
protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
while (0 < cb.readableBytes()) {
|
||||||
|
|
||||||
|
//check the Type of the TLV
|
||||||
|
byte yType = cb.readByte();
|
||||||
|
yType = (byte) (yType & (YTYPE_SHIFT_VALUE));
|
||||||
|
byte hLength = cb.readByte();
|
||||||
|
|
||||||
|
PcepValueType subObj;
|
||||||
|
|
||||||
|
switch (yType) {
|
||||||
|
|
||||||
|
case IPv4SubObject.TYPE:
|
||||||
|
subObj = IPv4SubObject.read(cb);
|
||||||
|
break;
|
||||||
|
case IPv6SubObject.TYPE:
|
||||||
|
byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH];
|
||||||
|
cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH);
|
||||||
|
subObj = new IPv6SubObject(ipv6Value);
|
||||||
|
break;
|
||||||
|
case AutonomousSystemTlv.TYPE:
|
||||||
|
subObj = AutonomousSystemTlv.read(cb);
|
||||||
|
break;
|
||||||
|
case PathKeySubObject.TYPE:
|
||||||
|
subObj = PathKeySubObject.read(cb);
|
||||||
|
break;
|
||||||
|
case SrEroSubObject.TYPE:
|
||||||
|
subObj = SrEroSubObject.read(cb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("Unexpected sub object. Type: " + (int) yType);
|
||||||
|
}
|
||||||
|
// Check for the padding
|
||||||
|
int pad = hLength % 4;
|
||||||
|
if (0 < pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
if (pad <= cb.readableBytes()) {
|
||||||
|
cb.skipBytes(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
llSubObjects.add(subObj);
|
||||||
|
}
|
||||||
|
if (0 < cb.readableBytes()) {
|
||||||
|
throw new PcepParseException("Subobject parsing error. Extra bytes received.");
|
||||||
|
}
|
||||||
|
return llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
int objLenIndex = eroObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Failed to write ERO object header. Index " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update object length now
|
||||||
|
int length = cb.writerIndex() - objStartIndex;
|
||||||
|
cb.setShort(objLenIndex, (short) length);
|
||||||
|
//will be helpful during print().
|
||||||
|
eroObjHeader.setObjLen((short) length);
|
||||||
|
|
||||||
|
//As per RFC the length of object should be multiples of 4
|
||||||
|
int pad = length % 4;
|
||||||
|
|
||||||
|
if (pad != 0) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; i++) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
length = length + pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
objLenIndex = cb.writerIndex();
|
||||||
|
return objLenIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP ERO object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepEroObject.Builder {
|
||||||
|
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
private PcepObjectHeader eroObjHeader;
|
||||||
|
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject build() {
|
||||||
|
|
||||||
|
PcepObjectHeader eroObjHeader = this.bIsHeaderSet ? this.eroObjHeader : DEFAULT_ERO_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
eroObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
eroObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepEroObjectVer1(eroObjHeader, this.llSubObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getEroObjHeader() {
|
||||||
|
return this.eroObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setEroObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.eroObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getSubObjects() {
|
||||||
|
return this.llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("ERO OBJECT");
|
||||||
|
eroObjHeader.print();
|
||||||
|
log.debug("SUBOBJECTS:");
|
||||||
|
ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("ero obj Header", eroObjHeader)
|
||||||
|
.add("Sub-Objects", llSubObjects)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,213 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepAttribute;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepCloseMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEndPointsObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEroObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepFactory;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepInitiateMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspaObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessage;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMetricObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMsgPath;
|
||||||
|
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
|
||||||
|
public class PcepFactoryVer1 implements PcepFactory {
|
||||||
|
|
||||||
|
public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepOpenMsg.Builder buildOpenMsg() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepOpenObject.Builder buildOpenObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepKeepaliveMsg.Builder buildKeepaliveMsg() {
|
||||||
|
return new PcepKeepaliveMsgVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepCloseMsg.Builder buildCloseMsg() {
|
||||||
|
return new PcepCloseMsgVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepUpdateMsg.Builder buildUpdateMsg() {
|
||||||
|
return new PcepUpdateMsgVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepReportMsg.Builder buildReportMsg() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepInitiateMsg.Builder buildPcepInitiateMsg() {
|
||||||
|
return new PcepInitiateMsgVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject.Builder buildLspObject() {
|
||||||
|
return new PcepLspObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMessageReader<PcepMessage> getReader() {
|
||||||
|
return PcepMessageVer1.READER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject.Builder buildSrpObject() {
|
||||||
|
return new PcepSrpObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEndPointsObject.Builder buildEndPointsObject() {
|
||||||
|
return new PcepEndPointsObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject.Builder buildEroObject() {
|
||||||
|
return new PcepEroObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepRroObject.Builder buildRroObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspaObject.Builder buildLspaObject() {
|
||||||
|
return new PcepLspaObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepIroObject.Builder buildIroObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMetricObject.Builder buildMetricObject() {
|
||||||
|
return new PcepMetricObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepBandwidthObject.Builder buildBandwidthObject() {
|
||||||
|
return new PcepBandwidthObjectVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMsgPath.Builder buildPcepMsgPath() {
|
||||||
|
return new PcepMsgPathVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepStateReport.Builder buildPcepStateReport() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepUpdateRequest.Builder buildPcepUpdateRequest() {
|
||||||
|
return new PcepUpdateRequestVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcInitiatedLspRequest.Builder buildPcInitiatedLspRequest() {
|
||||||
|
return new PcInitiatedLspRequestVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute.Builder buildPcepAttribute() {
|
||||||
|
return new PcepAttributeVer1.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepLabelUpdateMsg.Builder buildPcepLabelUpdateMsg() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepLabelUpdate.Builder buildPcepLabelUpdateObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepLabelObject.Builder buildLabelObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepErrorMsg.Builder buildPcepErrorMsg() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepErrorObject.Builder buildPcepErrorObject() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency.Builder buildFecIpv4Adjacency() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepErrorInfo.Builder buildPcepErrorInfo() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.onosproject.pcepio.protocol.PcepError.Builder buildPcepError() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,334 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepAttribute;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEndPointsObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEroObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepInitiateMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageWriter;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepType;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
class PcepInitiateMsgVer1 implements PcepInitiateMsg {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepInitiateMsgVer1.class);
|
||||||
|
|
||||||
|
// Ref : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03, section 5.1
|
||||||
|
/* <PCInitiate Message> ::= <Common Header>
|
||||||
|
* <PCE-initiated-lsp-list>
|
||||||
|
* Where:
|
||||||
|
* <PCE-initiated-lsp-list> ::= <PCE-initiated-lsp-request>[<PCE-initiated-lsp-list>]
|
||||||
|
* <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>)
|
||||||
|
* <PCE-initiated-lsp-instantiation> ::= <SRP>
|
||||||
|
* <LSP>
|
||||||
|
* <END-POINTS>
|
||||||
|
* <ERO>
|
||||||
|
* [<attribute-list>]
|
||||||
|
* <PCE-initiated-lsp-deletion> ::= <SRP>
|
||||||
|
* <LSP>
|
||||||
|
*/
|
||||||
|
|
||||||
|
static final byte PACKET_VERSION = 1;
|
||||||
|
/* considering LspDelete Request PcInitiate msg will contain
|
||||||
|
* common header
|
||||||
|
* srp object
|
||||||
|
* lsp object
|
||||||
|
* so min length for this can be
|
||||||
|
* PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+SrpObjectMinLen(12)+LspObjectMinLen(8)
|
||||||
|
*/
|
||||||
|
public static final short PACKET_MINIMUM_LENGTH = 24;
|
||||||
|
public static final short MINIMUM_COMMON_HEADER_LENGTH = 4;
|
||||||
|
public static final PcepType MSG_TYPE = PcepType.INITIATE;
|
||||||
|
private LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList;
|
||||||
|
public static final PcepInitiateMsgVer1.Reader READER = new Reader();
|
||||||
|
|
||||||
|
static class Reader implements PcepMessageReader<PcepInitiateMsg> {
|
||||||
|
|
||||||
|
LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepInitiateMsg readFrom(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
|
||||||
|
|
||||||
|
byte version = cb.readByte();
|
||||||
|
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
|
||||||
|
if (version != PACKET_VERSION) {
|
||||||
|
throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), received=" + version);
|
||||||
|
}
|
||||||
|
byte type = cb.readByte();
|
||||||
|
if (type != MSG_TYPE.getType()) {
|
||||||
|
throw new PcepParseException("Wrong type. Expected=PcepType.INITIATE(12), recived=" + type);
|
||||||
|
}
|
||||||
|
short length = cb.readShort();
|
||||||
|
|
||||||
|
if (length < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Wrong length. Initiate message length expected to be >= "
|
||||||
|
+ PACKET_MINIMUM_LENGTH + ", but received=" + length);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("reading PcInitiate message of length " + length);
|
||||||
|
|
||||||
|
// parse Start initiate/deletion list
|
||||||
|
if (!parsePcInitiatedLspRequestList(cb)) {
|
||||||
|
throw new PcepParseException("Parsing PCE-initiated-lsp-Request-list failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepInitiateMsgVer1(llPcInitiatedLspRequestList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To parse PcInitiatedLspRequestList from PcInitiate Message.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return true if parsing PcInitiatedLspRequestList is success, false otherwise
|
||||||
|
* @throws PcepParseException while parsing from channel buffer
|
||||||
|
*/
|
||||||
|
public boolean parsePcInitiatedLspRequestList(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
boolean isDelLspRequest = false;
|
||||||
|
|
||||||
|
if (null == cb) {
|
||||||
|
throw new PcepParseException("Channel buffer is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (0 < cb.readableBytes()) {
|
||||||
|
PcInitiatedLspRequest pceInitLspReq = new PcInitiatedLspRequestVer1();
|
||||||
|
|
||||||
|
//store SRP object
|
||||||
|
PcepSrpObject srpObj;
|
||||||
|
srpObj = PcepSrpObjectVer1.read(cb);
|
||||||
|
pceInitLspReq.setSrpObject(srpObj);
|
||||||
|
isDelLspRequest = srpObj.getRFlag();
|
||||||
|
|
||||||
|
//store LSP object
|
||||||
|
PcepLspObject lspObj;
|
||||||
|
lspObj = PcepLspObjectVer1.read(cb);
|
||||||
|
pceInitLspReq.setLspObject(lspObj);
|
||||||
|
|
||||||
|
/* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects
|
||||||
|
* so if R bit is not set then we should read for Ero and EndPoint objects also.
|
||||||
|
*/
|
||||||
|
if (!isDelLspRequest) {
|
||||||
|
|
||||||
|
//store EndPoint object
|
||||||
|
PcepEndPointsObject endPointObj;
|
||||||
|
endPointObj = PcepEndPointsObjectVer1.read(cb);
|
||||||
|
pceInitLspReq.setEndPointsObject(endPointObj);
|
||||||
|
|
||||||
|
//store ERO object
|
||||||
|
PcepEroObject eroObj;
|
||||||
|
eroObj = PcepEroObjectVer1.read(cb);
|
||||||
|
pceInitLspReq.setEroObject(eroObj);
|
||||||
|
|
||||||
|
if (cb.readableBytes() > MINIMUM_COMMON_HEADER_LENGTH) {
|
||||||
|
pceInitLspReq.setPcepAttribute(PcepAttributeVer1.read(cb));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
llPcInitiatedLspRequestList.add(pceInitLspReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize PcInitiatedLspRequest.
|
||||||
|
*
|
||||||
|
* @param llPcInitiatedLspRequestList list of PcInitiatedLspRequest
|
||||||
|
*/
|
||||||
|
PcepInitiateMsgVer1(LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList) {
|
||||||
|
|
||||||
|
if (llPcInitiatedLspRequestList == null) {
|
||||||
|
throw new NullPointerException("PcInitiatedLspRequestList cannot be null.");
|
||||||
|
}
|
||||||
|
this.llPcInitiatedLspRequestList = llPcInitiatedLspRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP initiate message.
|
||||||
|
*/
|
||||||
|
static class Builder implements PcepInitiateMsg.Builder {
|
||||||
|
|
||||||
|
// Pcep initiate message fields
|
||||||
|
LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return PcepType.INITIATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepInitiateMsg build() {
|
||||||
|
return new PcepInitiateMsgVer1(this.llPcInitiatedLspRequestList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList() {
|
||||||
|
return this.llPcInitiatedLspRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) {
|
||||||
|
this.llPcInitiatedLspRequestList = ll;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
WRITER.write(cb, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Writer WRITER = new Writer();
|
||||||
|
|
||||||
|
static class Writer implements PcepMessageWriter<PcepInitiateMsgVer1> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ChannelBuffer cb, PcepInitiateMsgVer1 message) throws PcepParseException {
|
||||||
|
|
||||||
|
boolean isDelLspRequest = false;
|
||||||
|
int startIndex = cb.writerIndex();
|
||||||
|
// first 3 bits set to version
|
||||||
|
cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
|
||||||
|
// message type 0xC
|
||||||
|
cb.writeByte(MSG_TYPE.getType());
|
||||||
|
// length is length of variable message, will be updated at the end
|
||||||
|
// Store the position of message
|
||||||
|
// length in buffer
|
||||||
|
int msgLenIndex = cb.writerIndex();
|
||||||
|
cb.writeShort(0);
|
||||||
|
|
||||||
|
ListIterator<PcInitiatedLspRequest> listIterator = message.llPcInitiatedLspRequestList.listIterator();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
|
||||||
|
PcInitiatedLspRequest listReq = listIterator.next();
|
||||||
|
|
||||||
|
//Srp Object is mandatory
|
||||||
|
PcepSrpObject srpObj = listReq.getSrpObject();
|
||||||
|
if (srpObj instanceof PcepSrpObject) {
|
||||||
|
isDelLspRequest = srpObj.getRFlag();
|
||||||
|
srpObj.write(cb);
|
||||||
|
} else {
|
||||||
|
throw new PcepParseException("SRP Object is mandatory for PcInitiate message.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//LSP Object is mandatory
|
||||||
|
PcepLspObject lspObj = listReq.getLspObject();
|
||||||
|
if (lspObj instanceof PcepLspObject) {
|
||||||
|
lspObj.write(cb);
|
||||||
|
} else {
|
||||||
|
throw new PcepParseException("LSP Object is mandatory for PcInitiate message.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects
|
||||||
|
* so if R bit is not set then we should read for Ero and EndPoint objects also.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!isDelLspRequest) {
|
||||||
|
|
||||||
|
//EndPoints object is mandatory
|
||||||
|
PcepEndPointsObject endPointObj = listReq.getEndPointsObject();
|
||||||
|
if (endPointObj instanceof PcepEndPointsObject) {
|
||||||
|
endPointObj.write(cb);
|
||||||
|
} else {
|
||||||
|
throw new PcepParseException("End points Object is mandatory for PcInitiate message.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ero object is mandatory
|
||||||
|
PcepEroObject eroObj = listReq.getEroObject();
|
||||||
|
if (eroObj instanceof PcepEroObject) {
|
||||||
|
eroObj.write(cb);
|
||||||
|
} else {
|
||||||
|
throw new PcepParseException("ERO Object is mandatory for PcInitiate message.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//PcepAttribute is optional
|
||||||
|
PcepAttribute pcepAttribute = listReq.getPcepAttribute();
|
||||||
|
if (pcepAttribute instanceof PcepAttribute) {
|
||||||
|
pcepAttribute.write(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PCInitiate message length field
|
||||||
|
int length = cb.writerIndex() - startIndex;
|
||||||
|
cb.setShort(msgLenIndex, (short) length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return MSG_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList() {
|
||||||
|
return this.llPcInitiatedLspRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) {
|
||||||
|
this.llPcInitiatedLspRequestList = ll;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("PCEP INITIATE MESSAGE");
|
||||||
|
ListIterator<PcInitiatedLspRequest> listIterator = llPcInitiatedLspRequestList.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("PC initiaited lsp request list", llPcInitiatedLspRequestList)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepIroObject;
|
||||||
|
import org.onosproject.pcepio.types.IPv4SubObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
// (Sub-objects) //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
The IRO Object format
|
||||||
|
|
||||||
|
Each IPV4 suboject
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | IPv4 address (4 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv4 address (continued) | Prefix Length | Resvd |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
public class PcepIroObjectVer1 implements PcepIroObject {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepIroObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte IRO_OBJ_TYPE = 1;
|
||||||
|
public static final byte IRO_OBJ_CLASS = 10;
|
||||||
|
public static final byte IRO_OBJECT_VERSION = 1;
|
||||||
|
public static final short IRO_OBJ_MINIMUM_LENGTH = 12;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
public static final int YTYPE_SHIFT_VALUE = 0x7F;
|
||||||
|
|
||||||
|
public static final PcepObjectHeader DEFAULT_IRO_OBJECT_HEADER = new PcepObjectHeader(IRO_OBJ_CLASS, IRO_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, IRO_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private short iroObjType = 0;
|
||||||
|
private byte yLength;
|
||||||
|
private byte yPrefixLength;
|
||||||
|
private byte yResvd;
|
||||||
|
private PcepObjectHeader iroObjHeader;
|
||||||
|
private LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public PcepIroObjectVer1() {
|
||||||
|
this.iroObjHeader = null;
|
||||||
|
this.iroObjType = 0;
|
||||||
|
this.yLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param iroObjHeader IRO object header
|
||||||
|
* @param llSubObjects list of sub-objects
|
||||||
|
*/
|
||||||
|
public PcepIroObjectVer1(PcepObjectHeader iroObjHeader, LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
this.iroObjHeader = iroObjHeader;
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns object header.
|
||||||
|
*
|
||||||
|
* @return iroObjHeader IRO object header
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getIroObjHeader() {
|
||||||
|
return this.iroObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets IRO Object Header.
|
||||||
|
*
|
||||||
|
* @param obj IRO object header
|
||||||
|
*/
|
||||||
|
public void setIroObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.iroObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getSubObjects() {
|
||||||
|
return this.llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSubObjects(LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and return object of PcepIroObject.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return object of PcepIroObject
|
||||||
|
* @throws PcepParseException while parsing from channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepIroObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader iroObjHeader;
|
||||||
|
LinkedList<PcepValueType> llSubObjects;
|
||||||
|
|
||||||
|
iroObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
//take only IroObject buffer.
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(iroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
|
||||||
|
llSubObjects = parseSubObjects(tempCb);
|
||||||
|
return new PcepIroObjectVer1(iroObjHeader, llSubObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns linked list of sub objects.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return linked list of sub objects
|
||||||
|
* @throws PcepParseException while parsing subobjects from channel buffer
|
||||||
|
*/
|
||||||
|
protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
while (0 < cb.readableBytes()) {
|
||||||
|
|
||||||
|
//check the Type of the Subobjects.
|
||||||
|
byte yType = cb.readByte();
|
||||||
|
yType = (byte) (yType & (YTYPE_SHIFT_VALUE));
|
||||||
|
byte hLength = cb.readByte();
|
||||||
|
|
||||||
|
PcepValueType subObj;
|
||||||
|
switch (yType) {
|
||||||
|
|
||||||
|
case IPv4SubObject.TYPE:
|
||||||
|
subObj = IPv4SubObject.read(cb);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("Invalid sub object. Type: " + (int) yType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the padding
|
||||||
|
int pad = hLength % 4;
|
||||||
|
if (0 < pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
if (pad <= cb.readableBytes()) {
|
||||||
|
cb.skipBytes(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
llSubObjects.add(subObj);
|
||||||
|
}
|
||||||
|
return llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
int objLenIndex = iroObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException(" ObjectLength is " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update object length now
|
||||||
|
int length = cb.writerIndex() - objStartIndex;
|
||||||
|
//will be helpful during print().
|
||||||
|
iroObjHeader.setObjLen((short) length);
|
||||||
|
// As per RFC the length of object should be
|
||||||
|
// multiples of 4
|
||||||
|
int pad = length % 4;
|
||||||
|
if (pad != 0) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; i++) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
length = length + pad;
|
||||||
|
}
|
||||||
|
cb.setShort(objLenIndex, (short) length);
|
||||||
|
objLenIndex = cb.writerIndex();
|
||||||
|
return objLenIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder implements PcepIroObject.Builder {
|
||||||
|
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
|
||||||
|
private PcepObjectHeader iroObjHeader;
|
||||||
|
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepIroObject build() {
|
||||||
|
|
||||||
|
PcepObjectHeader iroObjHeader = this.bIsHeaderSet ? this.iroObjHeader : DEFAULT_IRO_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
iroObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
iroObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepIroObjectVer1(iroObjHeader, this.llSubObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getIroObjHeader() {
|
||||||
|
return this.iroObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIroObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.iroObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getSubObjects() {
|
||||||
|
return this.llSubObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) {
|
||||||
|
this.llSubObjects = llSubObjects;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("IRO OBJECT");
|
||||||
|
iroObjHeader.print();
|
||||||
|
log.debug("SUBOBJECTS:");
|
||||||
|
ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("IRO object header", iroObjHeader)
|
||||||
|
.add("List of sub object", llSubObjects)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageWriter;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepType;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
class PcepKeepaliveMsgVer1 implements PcepKeepaliveMsg {
|
||||||
|
|
||||||
|
/*
|
||||||
|
<Keepalive Message>::= <Common Header>
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Ver | Flags | Message-Type | Message-Length |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepKeepaliveMsgVer1.class);
|
||||||
|
// Pcep version: 1
|
||||||
|
public static final byte PACKET_VERSION = 1;
|
||||||
|
public static final int PACKET_MINIMUM_LENGTH = 4;
|
||||||
|
public static final PcepType MSG_TYPE = PcepType.KEEP_ALIVE;
|
||||||
|
|
||||||
|
public static final PcepKeepaliveMsgVer1.Reader READER = new Reader();
|
||||||
|
|
||||||
|
static class Reader implements PcepMessageReader<PcepKeepaliveMsg> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepKeepaliveMsg readFrom(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Packet size is less than the minimum required length.");
|
||||||
|
}
|
||||||
|
// fixed value property version == 1
|
||||||
|
byte version = cb.readByte();
|
||||||
|
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
|
||||||
|
if (version != PACKET_VERSION) {
|
||||||
|
throw new PcepParseException("Wrong version: Expected=PcepVersion.KEEP_ALIVE_1(2), got=" + version);
|
||||||
|
}
|
||||||
|
// fixed value property type == 2
|
||||||
|
byte type = cb.readByte();
|
||||||
|
if (type != MSG_TYPE.getType()) {
|
||||||
|
throw new PcepParseException("Wrong type: Expected=PcepType.KEEP_ALIVE_1(2), got=" + type);
|
||||||
|
}
|
||||||
|
short length = cb.readShort();
|
||||||
|
if (length < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
|
||||||
|
+ length);
|
||||||
|
}
|
||||||
|
return new PcepKeepaliveMsgVer1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
PcepKeepaliveMsgVer1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Builder implements PcepKeepaliveMsg.Builder {
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return PcepType.KEEP_ALIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepKeepaliveMsg build() {
|
||||||
|
return new PcepKeepaliveMsgVer1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(ChannelBuffer cb) {
|
||||||
|
WRITER.write(cb, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Writer WRITER = new Writer();
|
||||||
|
|
||||||
|
static class Writer implements PcepMessageWriter<PcepKeepaliveMsgVer1> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ChannelBuffer cb, PcepKeepaliveMsgVer1 message) {
|
||||||
|
int startIndex = cb.writerIndex();
|
||||||
|
// first 3 bits set to version
|
||||||
|
cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
|
||||||
|
// message type
|
||||||
|
cb.writeByte(MSG_TYPE.getType());
|
||||||
|
// length is length of variable message, will be updated at the end
|
||||||
|
// Store the position of message
|
||||||
|
// length in buffer
|
||||||
|
int msgLenIndex = cb.writerIndex();
|
||||||
|
cb.writeShort((short) 0);
|
||||||
|
// update message length field
|
||||||
|
int length = cb.writerIndex() - startIndex;
|
||||||
|
cb.setShort(msgLenIndex, (short) length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return MSG_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("KEEPALIVE MESSAGE");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,593 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
|
||||||
|
import org.onosproject.pcepio.types.StatefulLspErrorCodeTlv;
|
||||||
|
import org.onosproject.pcepio.types.StatefulRsvpErrorSpecTlv;
|
||||||
|
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
message format.
|
||||||
|
Reference : draft-ietf-pce-stateful-pce-11, section 7.3.
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Object-Class | OT |Res|P|I| Object Length (bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| PLSP-ID | Flag | O|A|R|S|D|
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// TLVs //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
The LSP Object format
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PcepLspObjectVer1 implements PcepLspObject {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte LSP_OBJ_TYPE = 1;
|
||||||
|
public static final byte LSP_OBJ_CLASS = 32;
|
||||||
|
public static final byte LSP_OBJECT_VERSION = 1;
|
||||||
|
|
||||||
|
// LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(4)+TlvAssumedMinLength(8)
|
||||||
|
public static final short LSP_OBJ_MINIMUM_LENGTH = 16;
|
||||||
|
|
||||||
|
public static final int DEFAULT_PLSPID = 0;
|
||||||
|
public static final byte DEFAULT_OFLAG = 1;
|
||||||
|
public static final boolean DEFAULT_AFLAG = false;
|
||||||
|
public static final boolean DEFAULT_RFLAG = false;
|
||||||
|
public static final boolean DEFAULT_SFLAG = false;
|
||||||
|
public static final boolean DEFAULT_DFLAG = false;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
public static final int PLSPID_SHIFT_VALUE = 12;
|
||||||
|
public static final int OFLAG_SHIFT_VALUE = 4;
|
||||||
|
public static final int AFLAG_SHIFT_VALUE = 3;
|
||||||
|
public static final int RFLAG_SHIFT_VALUE = 2;
|
||||||
|
public static final int SFLAG_SHIFT_VALUE = 1;
|
||||||
|
public static final int PLSPID_TEMP_SHIFT_VALUE = 0xFFFFF000;
|
||||||
|
public static final int OFLAG_TEMP_SHIFT_VALUE = 0x70;
|
||||||
|
public static final int AFLAG_TEMP_SHIFT_VALUE = 0x08;
|
||||||
|
public static final int RFLAG_TEMP_SHIFT_VALUE = 0x04;
|
||||||
|
public static final int SFLAG_TEMP_SHIFT_VALUE = 0x02;
|
||||||
|
public static final int DFLAG_TEMP_SHIFT_VALUE = 0x01;
|
||||||
|
public static final int BIT_SET = 1;
|
||||||
|
public static final int BIT_RESET = 0;
|
||||||
|
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_LSP_OBJECT_HEADER = new PcepObjectHeader(LSP_OBJ_CLASS, LSP_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSP_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader lspObjHeader;
|
||||||
|
private int iPlspId;
|
||||||
|
// 3-bits
|
||||||
|
private byte yOFlag;
|
||||||
|
private boolean bAFlag;
|
||||||
|
private boolean bRFlag;
|
||||||
|
private boolean bSFlag;
|
||||||
|
private boolean bDFlag;
|
||||||
|
|
||||||
|
// Optional TLV
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all the member variables.
|
||||||
|
*
|
||||||
|
* @param lspObjHeader lsp object header
|
||||||
|
* @param iPlspId plsp id
|
||||||
|
* @param yOFlag O flag
|
||||||
|
* @param bAFlag A flag
|
||||||
|
* @param bRFlag R flag
|
||||||
|
* @param bSFlag S flag
|
||||||
|
* @param bDFlag D flag
|
||||||
|
* @param llOptionalTlv list of optional tlv
|
||||||
|
*/
|
||||||
|
public PcepLspObjectVer1(PcepObjectHeader lspObjHeader, int iPlspId, byte yOFlag, boolean bAFlag, boolean bRFlag,
|
||||||
|
boolean bSFlag, boolean bDFlag, LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
|
||||||
|
this.lspObjHeader = lspObjHeader;
|
||||||
|
this.iPlspId = iPlspId;
|
||||||
|
this.yOFlag = yOFlag;
|
||||||
|
this.bAFlag = bAFlag;
|
||||||
|
this.bRFlag = bRFlag;
|
||||||
|
this.bSFlag = bSFlag;
|
||||||
|
this.bDFlag = bDFlag;
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets lsp Object Header.
|
||||||
|
*
|
||||||
|
* @param obj lsp object header
|
||||||
|
*/
|
||||||
|
public void setLspObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.lspObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlspId(int iPlspId) {
|
||||||
|
this.iPlspId = iPlspId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOFlag(byte yOFlag) {
|
||||||
|
this.yOFlag = yOFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAFlag(boolean bAFlag) {
|
||||||
|
this.bAFlag = bAFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRFlag(boolean bRFlag) {
|
||||||
|
this.bRFlag = bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSFlag(boolean bSFlag) {
|
||||||
|
this.bSFlag = bSFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDFlag(boolean bDFlag) {
|
||||||
|
this.bDFlag = bDFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns lsp object header.
|
||||||
|
*
|
||||||
|
* @return lspObjHeader
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getLspObjHeader() {
|
||||||
|
return this.lspObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlspId() {
|
||||||
|
return this.iPlspId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getOFlag() {
|
||||||
|
return this.yOFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAFlag() {
|
||||||
|
return this.bAFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getRFlag() {
|
||||||
|
return this.bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getSFlag() {
|
||||||
|
return this.bSFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getDFlag() {
|
||||||
|
return this.bDFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse channel buffer and returns object of PcepLspObject.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return object of PcepLspObject
|
||||||
|
* @throws PcepParseException when lsp object is not present in channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepLspObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader lspObjHeader;
|
||||||
|
int iPlspId;
|
||||||
|
// 3-bits
|
||||||
|
byte yOFlag;
|
||||||
|
boolean bAFlag;
|
||||||
|
boolean bRFlag;
|
||||||
|
boolean bSFlag;
|
||||||
|
boolean bDFlag;
|
||||||
|
|
||||||
|
// Optional TLV
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
lspObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
if (lspObjHeader.getObjClass() != PcepLspObjectVer1.LSP_OBJ_CLASS) {
|
||||||
|
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_8);
|
||||||
|
}
|
||||||
|
//take only LspObject buffer.
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(lspObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
|
||||||
|
|
||||||
|
Integer iTemp = tempCb.readInt();
|
||||||
|
iPlspId = (iTemp & PLSPID_TEMP_SHIFT_VALUE) >> PLSPID_SHIFT_VALUE;
|
||||||
|
Integer iX = (iTemp & OFLAG_TEMP_SHIFT_VALUE) >> OFLAG_SHIFT_VALUE;
|
||||||
|
yOFlag = iX.byteValue();
|
||||||
|
iX = (iTemp & AFLAG_TEMP_SHIFT_VALUE) >> AFLAG_SHIFT_VALUE;
|
||||||
|
bAFlag = (iX > 0) ? true : false;
|
||||||
|
iX = (iTemp & RFLAG_TEMP_SHIFT_VALUE) >> RFLAG_SHIFT_VALUE;
|
||||||
|
bRFlag = (iX > 0) ? true : false;
|
||||||
|
iX = (iTemp & SFLAG_TEMP_SHIFT_VALUE) >> SFLAG_SHIFT_VALUE;
|
||||||
|
bSFlag = (iX > 0) ? true : false;
|
||||||
|
iX = iTemp & DFLAG_TEMP_SHIFT_VALUE;
|
||||||
|
bDFlag = (iX > 0) ? true : false;
|
||||||
|
|
||||||
|
// parse optional TLV
|
||||||
|
llOptionalTlv = parseOptionalTlv(tempCb);
|
||||||
|
|
||||||
|
return new PcepLspObjectVer1(lspObjHeader, iPlspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
int objLenIndex = lspObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Failed to write lsp object header. Index " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
int iTemp = iPlspId << PLSPID_SHIFT_VALUE;
|
||||||
|
iTemp = iTemp | (yOFlag << OFLAG_SHIFT_VALUE);
|
||||||
|
byte bFlag;
|
||||||
|
iTemp = bAFlag ? (iTemp | AFLAG_TEMP_SHIFT_VALUE) : iTemp;
|
||||||
|
|
||||||
|
bFlag = (bRFlag) ? (byte) BIT_SET : BIT_RESET;
|
||||||
|
iTemp = iTemp | (bFlag << RFLAG_SHIFT_VALUE);
|
||||||
|
bFlag = (bSFlag) ? (byte) BIT_SET : BIT_RESET;
|
||||||
|
iTemp = iTemp | (bFlag << SFLAG_SHIFT_VALUE);
|
||||||
|
bFlag = (bDFlag) ? (byte) BIT_SET : BIT_RESET;
|
||||||
|
iTemp = iTemp | bFlag;
|
||||||
|
cb.writeInt(iTemp);
|
||||||
|
|
||||||
|
// Add optional TLV
|
||||||
|
packOptionalTlv(cb);
|
||||||
|
|
||||||
|
//Update object length now
|
||||||
|
int length = cb.writerIndex() - objStartIndex;
|
||||||
|
//will be helpful during print().
|
||||||
|
lspObjHeader.setObjLen((short) length);
|
||||||
|
// As per RFC the length of object should be
|
||||||
|
// multiples of 4
|
||||||
|
|
||||||
|
cb.setShort(objLenIndex, (short) length);
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Linked list of optional tlvs.
|
||||||
|
*
|
||||||
|
* @param cb of channel buffer.
|
||||||
|
* @return list of optional tlvs
|
||||||
|
* @throws PcepParseException when unsupported tlv is received
|
||||||
|
*/
|
||||||
|
protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llOutOptionalTlv;
|
||||||
|
|
||||||
|
llOutOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) {
|
||||||
|
|
||||||
|
PcepValueType tlv;
|
||||||
|
short hType = cb.readShort();
|
||||||
|
short hLength = cb.readShort();
|
||||||
|
int iValue = 0;
|
||||||
|
|
||||||
|
switch (hType) {
|
||||||
|
|
||||||
|
case StatefulIPv4LspIdentidiersTlv.TYPE:
|
||||||
|
tlv = StatefulIPv4LspIdentidiersTlv.read(cb);
|
||||||
|
break;
|
||||||
|
case StatefulLspErrorCodeTlv.TYPE:
|
||||||
|
iValue = cb.readInt();
|
||||||
|
tlv = new StatefulLspErrorCodeTlv(iValue);
|
||||||
|
break;
|
||||||
|
case StatefulRsvpErrorSpecTlv.TYPE:
|
||||||
|
tlv = StatefulRsvpErrorSpecTlv.read(cb);
|
||||||
|
break;
|
||||||
|
case SymbolicPathNameTlv.TYPE:
|
||||||
|
tlv = SymbolicPathNameTlv.read(cb, hLength);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("Received unsupported TLV type :" + hType);
|
||||||
|
}
|
||||||
|
// Check for the padding
|
||||||
|
int pad = hLength % 4;
|
||||||
|
if (0 < pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
if (pad <= cb.readableBytes()) {
|
||||||
|
cb.skipBytes(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
llOutOptionalTlv.add(tlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < cb.readableBytes()) {
|
||||||
|
|
||||||
|
throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
|
||||||
|
}
|
||||||
|
return llOutOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns writer index.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return length of bytes written to channel buffer
|
||||||
|
*/
|
||||||
|
protected int packOptionalTlv(ChannelBuffer cb) {
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
int startIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
PcepValueType tlv = listIterator.next();
|
||||||
|
|
||||||
|
if (null == tlv) {
|
||||||
|
log.debug("tlv is null from OptionalTlv list");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tlv.write(cb);
|
||||||
|
|
||||||
|
// need to take care of padding
|
||||||
|
int pad = tlv.getLength() % 4;
|
||||||
|
|
||||||
|
if (0 != pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; ++i) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb.writerIndex() - startIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP lsp Object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepLspObject.Builder {
|
||||||
|
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
private boolean bIsPlspIdSet = false;
|
||||||
|
private boolean bIsOFlagSet = false;
|
||||||
|
private boolean bIsRFlagSet = false;
|
||||||
|
private boolean bIsAFlagSet = false;
|
||||||
|
private boolean bIsDFlagSet = false;
|
||||||
|
private boolean bIsSFlagSet = false;
|
||||||
|
|
||||||
|
private PcepObjectHeader lspObjHeader;
|
||||||
|
private byte yOFlag;
|
||||||
|
private boolean bAFlag;
|
||||||
|
private boolean bDFlag;
|
||||||
|
private boolean bSFlag;
|
||||||
|
private boolean bRFlag;
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = null;
|
||||||
|
|
||||||
|
private int plspId;
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject build() {
|
||||||
|
PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.lspObjHeader : DEFAULT_LSP_OBJECT_HEADER;
|
||||||
|
|
||||||
|
int plspId = this.bIsPlspIdSet ? this.plspId : DEFAULT_PLSPID;
|
||||||
|
byte yOFlag = this.bIsOFlagSet ? this.yOFlag : DEFAULT_OFLAG;
|
||||||
|
boolean bAFlag = this.bIsAFlagSet ? this.bAFlag : DEFAULT_AFLAG;
|
||||||
|
boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG;
|
||||||
|
boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_SFLAG;
|
||||||
|
boolean bDFlag = this.bIsDFlagSet ? this.bDFlag : DEFAULT_DFLAG;
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
lspObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
lspObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepLspObjectVer1(lspObjHeader, plspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getLspObjHeader() {
|
||||||
|
return this.lspObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLspObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.lspObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlspId() {
|
||||||
|
return this.plspId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPlspId(int value) {
|
||||||
|
this.plspId = value;
|
||||||
|
this.bIsPlspIdSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getOFlag() {
|
||||||
|
return this.yOFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setOFlag(byte value) {
|
||||||
|
this.yOFlag = value;
|
||||||
|
this.bIsOFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAFlag() {
|
||||||
|
return this.bAFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setAFlag(boolean value) {
|
||||||
|
this.bAFlag = value;
|
||||||
|
this.bIsAFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getRFlag() {
|
||||||
|
return this.bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setRFlag(boolean value) {
|
||||||
|
this.bRFlag = value;
|
||||||
|
this.bIsRFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getSFlag() {
|
||||||
|
return this.bSFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSFlag(boolean value) {
|
||||||
|
this.bSFlag = value;
|
||||||
|
this.bIsSFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getDFlag() {
|
||||||
|
return this.bDFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setDFlag(boolean value) {
|
||||||
|
this.bDFlag = value;
|
||||||
|
this.bIsDFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("LSP OBJECT");
|
||||||
|
long lTemp = iPlspId & 0xFFFFFFFF;
|
||||||
|
log.debug("PLSP Id: " + lTemp);
|
||||||
|
lTemp = yOFlag & 0xFFFF;
|
||||||
|
log.debug("O Flag: " + lTemp);
|
||||||
|
lTemp = (bAFlag) ? 1 : 0;
|
||||||
|
log.debug("A Flag: " + lTemp);
|
||||||
|
lTemp = (bRFlag) ? 1 : 0;
|
||||||
|
log.debug("R Flag: " + lTemp);
|
||||||
|
lTemp = (bSFlag) ? 1 : 0;
|
||||||
|
log.debug("S Flag: " + lTemp);
|
||||||
|
lTemp = (bDFlag) ? 1 : 0;
|
||||||
|
log.debug("D Flag: " + lTemp);
|
||||||
|
|
||||||
|
log.debug("OPTIONAL TLV:");
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Plsp ID value", iPlspId)
|
||||||
|
.add("o flag", yOFlag)
|
||||||
|
.add("A flag", bAFlag)
|
||||||
|
.add("R flag", bRFlag)
|
||||||
|
.add("S flag", bSFlag)
|
||||||
|
.add("D flag", bDFlag)
|
||||||
|
.add("List of optional tlv", llOptionalTlv)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,552 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspaObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepLspaObjectVer1 implements PcepLspaObject {
|
||||||
|
|
||||||
|
/* LSPA Object Body Format
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Exclude-any |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Include-any |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Include-all |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Setup Prio | Holding Prio | Flags |L| Reserved |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
| Optional TLVs |
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepLspaObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte LSPA_OBJ_TYPE = 1;
|
||||||
|
public static final byte LSPA_OBJ_CLASS = 9;
|
||||||
|
public static final byte LSPA_OBJECT_VERSION = 1;
|
||||||
|
public static final short LSPA_OBJ_MINIMUM_LENGTH = 20;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_LSPA_OBJECT_HEADER = new PcepObjectHeader(LSPA_OBJ_CLASS, LSPA_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSPA_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
public static final int SETUP_PRIORITY_SHIFT_VALUE = 24;
|
||||||
|
public static final int HOLD_PRIORITY_SHIFT_VALUE = 16;
|
||||||
|
public static final int BFLAG_SHIFT_VALUE = 8;
|
||||||
|
public static final int LFLAG_SET = 1;
|
||||||
|
public static final int LFLAG_RESET = 0;
|
||||||
|
private PcepObjectHeader lspaObjHeader;
|
||||||
|
private int iExcludeAny;
|
||||||
|
private int iIncludeAny;
|
||||||
|
private int iIncludeAll;
|
||||||
|
private byte cSetupPriority;
|
||||||
|
private byte cHoldPriority;
|
||||||
|
private byte flags;
|
||||||
|
private byte reserved;
|
||||||
|
private boolean bLFlag;
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv; //Optional TLV
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param lspaObjHeader lspa object header
|
||||||
|
* @param bLFlag b l flag
|
||||||
|
* @param iExcludeAny excludeAny value
|
||||||
|
* @param iIncludeAny includeAny value
|
||||||
|
* @param iIncludeAll includeAll value
|
||||||
|
* @param cSetupPriority setup priority value
|
||||||
|
* @param cHoldPriority hold priority value
|
||||||
|
* @param llOptionalTlv list of optional tlv
|
||||||
|
*/
|
||||||
|
public PcepLspaObjectVer1(PcepObjectHeader lspaObjHeader, boolean bLFlag, int iExcludeAny, int iIncludeAny,
|
||||||
|
int iIncludeAll, byte cSetupPriority, byte cHoldPriority, LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
|
||||||
|
this.lspaObjHeader = lspaObjHeader;
|
||||||
|
this.bLFlag = bLFlag;
|
||||||
|
this.iExcludeAny = iExcludeAny;
|
||||||
|
this.iIncludeAny = iIncludeAny;
|
||||||
|
this.iIncludeAll = iIncludeAll;
|
||||||
|
this.cSetupPriority = cSetupPriority;
|
||||||
|
this.cHoldPriority = cHoldPriority;
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Object Header.
|
||||||
|
*
|
||||||
|
* @param obj lspa object header
|
||||||
|
*/
|
||||||
|
public void setLspaObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.lspaObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExcludeAny(int iExcludeAny) {
|
||||||
|
this.iExcludeAny = iExcludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIncludeAny(int iIncludeAny) {
|
||||||
|
this.iIncludeAny = iIncludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSetupPriority(byte cSetupPriority) {
|
||||||
|
this.cSetupPriority = cSetupPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHoldPriority(byte cHoldPriority) {
|
||||||
|
this.cHoldPriority = cHoldPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLFlag(boolean bLFlag) {
|
||||||
|
this.bLFlag = bLFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns lspa Object Header.
|
||||||
|
*
|
||||||
|
* @return lspa Object Header
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getLspaObjHeader() {
|
||||||
|
return this.lspaObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getExcludeAny() {
|
||||||
|
return this.iExcludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIncludeAny() {
|
||||||
|
return this.iIncludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIncludeAll() {
|
||||||
|
return this.iIncludeAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getSetupPriority() {
|
||||||
|
return this.cSetupPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getHoldPriority() {
|
||||||
|
return this.cHoldPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getLFlag() {
|
||||||
|
return this.bLFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIncludeAll(int value) {
|
||||||
|
this.iIncludeAll = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads channel buffer and returns object of PcepLspaObject.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer.
|
||||||
|
* @return object of PcepLspaObject
|
||||||
|
* @throws PcepParseException while parsing lspa object from channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepLspaObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
log.debug("LspaObject::read");
|
||||||
|
PcepObjectHeader lspaObjHeader;
|
||||||
|
int iExcludeAny;
|
||||||
|
int iIncludeAny;
|
||||||
|
int iIncludeAll;
|
||||||
|
byte cSetupPriority;
|
||||||
|
byte cHoldPriority;
|
||||||
|
boolean bLFlag;
|
||||||
|
byte flags;
|
||||||
|
|
||||||
|
// Optional TLV
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
|
||||||
|
lspaObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
//take only Lspa Object buffer.
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(lspaObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
|
||||||
|
iExcludeAny = tempCb.readInt();
|
||||||
|
iIncludeAny = tempCb.readInt();
|
||||||
|
iIncludeAll = tempCb.readInt();
|
||||||
|
cSetupPriority = tempCb.readByte();
|
||||||
|
cHoldPriority = tempCb.readByte();
|
||||||
|
flags = tempCb.readByte();
|
||||||
|
tempCb.readByte();
|
||||||
|
|
||||||
|
bLFlag = (flags & (byte) LFLAG_SET) == LFLAG_SET ? true : false;
|
||||||
|
|
||||||
|
llOptionalTlv = parseOptionalTlv(tempCb);
|
||||||
|
|
||||||
|
return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority,
|
||||||
|
cHoldPriority, llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
int objLenIndex = lspaObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Failed to write lspa object header. Index " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb.writeInt(iExcludeAny);
|
||||||
|
cb.writeInt(iIncludeAny);
|
||||||
|
cb.writeInt(iIncludeAll);
|
||||||
|
|
||||||
|
int iTemp = cSetupPriority << SETUP_PRIORITY_SHIFT_VALUE;
|
||||||
|
iTemp = iTemp | (cHoldPriority << HOLD_PRIORITY_SHIFT_VALUE);
|
||||||
|
byte bFlag;
|
||||||
|
bFlag = (bLFlag) ? (byte) LFLAG_SET : LFLAG_RESET;
|
||||||
|
iTemp = iTemp | (bFlag << BFLAG_SHIFT_VALUE);
|
||||||
|
cb.writeInt(iTemp);
|
||||||
|
|
||||||
|
// Add optional TLV
|
||||||
|
if (!packOptionalTlv(cb)) {
|
||||||
|
throw new PcepParseException("Faild to write lspa objects tlv to channel buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
short length = (short) (cb.writerIndex() - objStartIndex);
|
||||||
|
|
||||||
|
lspaObjHeader.setObjLen(length); //will be helpful during print().
|
||||||
|
|
||||||
|
//As per RFC the length of object should be multiples of 4
|
||||||
|
short pad = (short) (length % 4);
|
||||||
|
|
||||||
|
if (pad != 0) {
|
||||||
|
pad = (short) (4 - pad);
|
||||||
|
for (int i = 0; i < pad; i++) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
length = (short) (length + pad);
|
||||||
|
}
|
||||||
|
cb.setShort(objLenIndex, length);
|
||||||
|
return cb.writerIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse list of optional tlvs.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return list of optional tlvs.
|
||||||
|
* @throws PcepParseException when fails to parse optional tlv list.
|
||||||
|
*/
|
||||||
|
public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
return llOutOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes optional tlvs to channel buffer.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return true
|
||||||
|
*/
|
||||||
|
protected boolean packOptionalTlv(ChannelBuffer cb) {
|
||||||
|
int hTlvType;
|
||||||
|
int hTlvLength;
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
PcepValueType tlv = listIterator.next();
|
||||||
|
if (null == tlv) {
|
||||||
|
log.debug("Warning: tlv is null from OptionalTlv list");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hTlvType = tlv.getType();
|
||||||
|
hTlvLength = tlv.getLength();
|
||||||
|
if (0 == hTlvLength) {
|
||||||
|
log.debug("Warning: invalid length in tlv of OptionalTlv list");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cb.writeShort(hTlvType);
|
||||||
|
cb.writeShort(hTlvLength);
|
||||||
|
|
||||||
|
switch (hTlvType) {
|
||||||
|
//TODO: optional TLV for LSPA to be added
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.debug("Warning: PcepLspaObject: unknown tlv");
|
||||||
|
}
|
||||||
|
|
||||||
|
// As per RFC the length of object should
|
||||||
|
// be multiples of 4
|
||||||
|
int pad = hTlvLength % 4;
|
||||||
|
|
||||||
|
if (0 < pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
if (pad <= cb.readableBytes()) {
|
||||||
|
cb.skipBytes(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builder class for PCEP lspa object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepLspaObject.Builder {
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
|
||||||
|
private PcepObjectHeader lspaObjHeader;
|
||||||
|
|
||||||
|
private boolean bLFlag;
|
||||||
|
private int iExcludeAny;
|
||||||
|
private boolean bIsExcludeAnySet = false;
|
||||||
|
private int iIncludeAny;
|
||||||
|
private boolean bIsIncludeAnySet = false;
|
||||||
|
private int iIncludeAll;
|
||||||
|
private boolean bIsIncludeAllSet = false;
|
||||||
|
private byte cSetupPriority;
|
||||||
|
private boolean bIsSetupPrioritySet = false;
|
||||||
|
private byte cHoldPriority;
|
||||||
|
private boolean bIsHoldPrioritySet = false;
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspaObject build() throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader lspaObjHeader = this.bIsHeaderSet ? this.lspaObjHeader : DEFAULT_LSPA_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (!this.bIsExcludeAnySet) {
|
||||||
|
throw new PcepParseException("ExcludeAny NOT Set while building PcepLspaObject.");
|
||||||
|
}
|
||||||
|
if (!this.bIsIncludeAnySet) {
|
||||||
|
throw new PcepParseException("IncludeAny NOT Set while building PcepLspaObject.");
|
||||||
|
}
|
||||||
|
if (!this.bIsIncludeAllSet) {
|
||||||
|
throw new PcepParseException("IncludeAll NOT Set while building PcepLspaObject.");
|
||||||
|
}
|
||||||
|
if (!this.bIsSetupPrioritySet) {
|
||||||
|
throw new PcepParseException("Setup Priority NOT Set while building PcepLspaObject.");
|
||||||
|
}
|
||||||
|
if (!this.bIsHoldPrioritySet) {
|
||||||
|
throw new PcepParseException("Hold Priority NOT Set while building PcepLspaObject.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
lspaObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
lspaObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority,
|
||||||
|
cHoldPriority, llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getLspaObjHeader() {
|
||||||
|
return this.lspaObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLspaObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.lspaObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getLFlag() {
|
||||||
|
return this.bLFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLFlag(boolean value) {
|
||||||
|
this.bLFlag = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getExcludeAny() {
|
||||||
|
return this.iExcludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setExcludeAny(int value) {
|
||||||
|
this.iExcludeAny = value;
|
||||||
|
this.bIsExcludeAnySet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIncludeAny() {
|
||||||
|
return this.iIncludeAny;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIncludeAny(int value) {
|
||||||
|
this.iIncludeAny = value;
|
||||||
|
this.bIsIncludeAnySet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIncludeAll() {
|
||||||
|
return this.iIncludeAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIncludeAll(int value) {
|
||||||
|
this.iIncludeAll = value;
|
||||||
|
this.bIsIncludeAllSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getSetupPriority() {
|
||||||
|
return this.cSetupPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSetupPriority(byte value) {
|
||||||
|
this.cSetupPriority = value;
|
||||||
|
this.bIsSetupPrioritySet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getHoldPriority() {
|
||||||
|
return this.cHoldPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setHoldPriority(byte value) {
|
||||||
|
this.cHoldPriority = value;
|
||||||
|
this.bIsHoldPrioritySet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("LSPA OBJECT");
|
||||||
|
long lTemp = flags & 0xFF;
|
||||||
|
lTemp = (bLFlag) ? 1 : 0;
|
||||||
|
log.debug("l Flag: " + lTemp);
|
||||||
|
lTemp = cSetupPriority & 0xFF;
|
||||||
|
log.debug("SetupPriority: " + lTemp);
|
||||||
|
lTemp = cHoldPriority & 0xFF;
|
||||||
|
log.debug("HoldPriority: " + lTemp);
|
||||||
|
lTemp = iIncludeAll & 0xFFFFFFFF;
|
||||||
|
log.debug("IncludeAll: " + lTemp);
|
||||||
|
lTemp = iIncludeAny & 0xFFFFFFFF;
|
||||||
|
log.debug("IncludeAny: " + lTemp);
|
||||||
|
lTemp = iExcludeAny & 0xFFFFFFFF;
|
||||||
|
log.debug("iExcludeAny: " + lTemp);
|
||||||
|
|
||||||
|
log.debug("OPTIONAL TLV:");
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("L flag", bLFlag)
|
||||||
|
.add("Setup priority", cSetupPriority)
|
||||||
|
.add("hold priority", cHoldPriority)
|
||||||
|
.add("Include all", iIncludeAll)
|
||||||
|
.add("Include any", iIncludeAny)
|
||||||
|
.add("Exclude any", iExcludeAny)
|
||||||
|
.add("List of optional tlv", llOptionalTlv)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepFactories;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessage;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public abstract class PcepMessageVer1 {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class);
|
||||||
|
|
||||||
|
// version: 1.0
|
||||||
|
static final byte WIRE_VERSION = 1;
|
||||||
|
static final int MINIMUM_LENGTH = 4;
|
||||||
|
static final int PACKET_VERSION = 1;
|
||||||
|
static final byte OPEN_MSG_TYPE = 0x1;
|
||||||
|
static final byte KEEPALIVE_MSG_TYPE = 0x2;
|
||||||
|
static final byte REPORT_MSG_TYPE = 0xa;
|
||||||
|
static final byte TE_REPORT_MSG_TYPE = 0xe;
|
||||||
|
static final byte UPDATE_MSG_TYPE = 0xb;
|
||||||
|
static final byte INITIATE_MSG_TYPE = 0xc;
|
||||||
|
static final byte CLOSE_MSG_TYPE = 0x7;
|
||||||
|
static final byte ERROR_MSG_TYPE = 0x6;
|
||||||
|
static final byte LABEL_UPDATE_MSG_TYPE = 0xD;
|
||||||
|
public static final int SHIFT_FLAG = 5;
|
||||||
|
static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
public static final PcepMessageVer1.Reader READER = new Reader();
|
||||||
|
|
||||||
|
static class Reader implements PcepMessageReader<PcepMessage> {
|
||||||
|
@Override
|
||||||
|
public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (cb.readableBytes() < MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Packet should have minimum length: " + MINIMUM_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int start = cb.readerIndex();
|
||||||
|
// fixed value property version == 1
|
||||||
|
byte version = cb.readByte();
|
||||||
|
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
|
||||||
|
if (version != (byte) PACKET_VERSION) {
|
||||||
|
throw new PcepParseException("Wrong version. Expected=PcepVersion.Message_1(1), got=" + version);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte type = cb.readByte();
|
||||||
|
short length = cb.readShort();
|
||||||
|
cb.readerIndex(start);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case OPEN_MSG_TYPE:
|
||||||
|
log.debug("OPEN MESSAGE is received");
|
||||||
|
// message type value 1 means it is open message
|
||||||
|
// return
|
||||||
|
// TODO: Read open message from channel buffer.
|
||||||
|
case KEEPALIVE_MSG_TYPE:
|
||||||
|
log.debug("KEEPALIVE MESSAGE is received");
|
||||||
|
// message type value 2 means it is Keepalive message
|
||||||
|
return PcepKeepaliveMsgVer1.READER.readFrom(cb.readBytes(length));
|
||||||
|
case ERROR_MSG_TYPE:
|
||||||
|
log.debug("ERROR MESSAGE is received");
|
||||||
|
// message type value 6 means it is error message
|
||||||
|
// return
|
||||||
|
// TODO: Read Error message from channel buffer.
|
||||||
|
case REPORT_MSG_TYPE:
|
||||||
|
log.debug("REPORT MESSAGE is received");
|
||||||
|
// message type value 10 means it is Report message
|
||||||
|
// return
|
||||||
|
// TODO: Read Report message from channel buffer.
|
||||||
|
case UPDATE_MSG_TYPE:
|
||||||
|
log.debug("UPDATE MESSAGE is received");
|
||||||
|
//message type value 11 means it is Update message
|
||||||
|
return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
|
||||||
|
case INITIATE_MSG_TYPE:
|
||||||
|
log.debug("INITIATE MESSAGE is received");
|
||||||
|
//message type value 12 means it is PcInitiate message
|
||||||
|
return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length));
|
||||||
|
case CLOSE_MSG_TYPE:
|
||||||
|
log.debug("CLOSE MESSAGE is received");
|
||||||
|
// message type value 7 means it is Close message
|
||||||
|
return PcepCloseMsgVer1.READER.readFrom(cb.readBytes(length));
|
||||||
|
case TE_REPORT_MSG_TYPE:
|
||||||
|
log.debug("TE REPORT MESSAGE is received");
|
||||||
|
// message type value 14 means it is TE REPORT message
|
||||||
|
// return
|
||||||
|
// TODO: Read TE Report message from channel buffer.
|
||||||
|
case LABEL_UPDATE_MSG_TYPE:
|
||||||
|
log.debug("LABEL UPDATE MESSAGE is received");
|
||||||
|
// message type value 13 means it is LABEL UPDATE message
|
||||||
|
// return
|
||||||
|
// TODO: Read Label update message from channel buffer.
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("ERROR: UNKNOWN MESSAGE is received. Msg Type: " + type);
|
||||||
|
}
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,387 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMetricObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
METRIC Object Body Format.
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Reserved | Flags |C|B| T |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| metric-value |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PcepMetricObjectVer1 implements PcepMetricObject {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepMetricObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte METRIC_OBJ_TYPE = 1;
|
||||||
|
public static final byte METRIC_OBJ_CLASS = 6;
|
||||||
|
public static final byte METRIC_OBJECT_VERSION = 1;
|
||||||
|
public static final short METRIC_OBJ_MINIMUM_LENGTH = 12;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
public static final int IFLAG_SHIFT_VALUE = 9;
|
||||||
|
public static final int BTYPE_SHIFT_VALUE = 8;
|
||||||
|
public static final int CFLAG_SET = 1;
|
||||||
|
public static final int CFLAG_RESET = 0;
|
||||||
|
public static final int BFLAG_SET = 1;
|
||||||
|
public static final int BFLAG_RESET = 0;
|
||||||
|
public static final byte CFLAG_CHECK = 0x02;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS,
|
||||||
|
METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
|
||||||
|
METRIC_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader metricObjHeader;
|
||||||
|
private int iMetricVal;
|
||||||
|
private byte yFlag; // 6-flags
|
||||||
|
private boolean bCFlag;
|
||||||
|
private boolean bBFlag;
|
||||||
|
private byte bType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public PcepMetricObjectVer1() {
|
||||||
|
this.metricObjHeader = null;
|
||||||
|
this.iMetricVal = 0;
|
||||||
|
this.yFlag = 0;
|
||||||
|
this.bCFlag = false;
|
||||||
|
this.bBFlag = false;
|
||||||
|
this.bType = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all member variables.
|
||||||
|
*
|
||||||
|
* @param metricObjHeader metric object header
|
||||||
|
* @param iMetricVal metric value
|
||||||
|
* @param yFlag Y flag
|
||||||
|
* @param bCFlag C flag
|
||||||
|
* @param bBFlag B flag
|
||||||
|
* @param bType Type value
|
||||||
|
*/
|
||||||
|
public PcepMetricObjectVer1(PcepObjectHeader metricObjHeader, int iMetricVal, byte yFlag, boolean bCFlag,
|
||||||
|
boolean bBFlag, byte bType) {
|
||||||
|
|
||||||
|
this.metricObjHeader = metricObjHeader;
|
||||||
|
this.iMetricVal = iMetricVal;
|
||||||
|
this.yFlag = yFlag;
|
||||||
|
this.bCFlag = bCFlag;
|
||||||
|
this.bBFlag = bBFlag;
|
||||||
|
this.bType = bType;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMetricVal(int value) {
|
||||||
|
this.iMetricVal = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricVal() {
|
||||||
|
return this.iMetricVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getYFlag() {
|
||||||
|
return this.yFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setYFlag(byte value) {
|
||||||
|
this.yFlag = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getCFlag() {
|
||||||
|
return this.bCFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCFlag(boolean value) {
|
||||||
|
this.bCFlag = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getBFlag() {
|
||||||
|
return this.bBFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBFlag(boolean value) {
|
||||||
|
this.bBFlag = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getBType() {
|
||||||
|
return this.bType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBType(byte value) {
|
||||||
|
this.bType = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets metric Object Header.
|
||||||
|
*
|
||||||
|
* @param obj metric object header
|
||||||
|
*/
|
||||||
|
public void setMetricObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.metricObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns metric Object Header.
|
||||||
|
*
|
||||||
|
* @return metricObjHeader
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getMetricObjHeader() {
|
||||||
|
return this.metricObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns object of PcepMetricObject.
|
||||||
|
*
|
||||||
|
* @param cb of channel buffer.
|
||||||
|
* @return object of PcepMetricObject
|
||||||
|
* @throws PcepParseException when metric object is not present in channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepMetricObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
log.debug("MetricObject::read");
|
||||||
|
PcepObjectHeader metricObjHeader;
|
||||||
|
int iMetricVal;
|
||||||
|
byte yFlag; // 6-flags
|
||||||
|
boolean bCFlag;
|
||||||
|
boolean bBFlag;
|
||||||
|
byte bType;
|
||||||
|
|
||||||
|
metricObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
if (metricObjHeader.getObjClass() != METRIC_OBJ_CLASS) {
|
||||||
|
throw new PcepParseException("This object is not a Metric Object. Object Class: "
|
||||||
|
+ metricObjHeader.getObjClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
//take only metric buffer.
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(metricObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
|
||||||
|
|
||||||
|
tempCb.readShort();
|
||||||
|
yFlag = tempCb.readByte();
|
||||||
|
bType = tempCb.readByte();
|
||||||
|
bCFlag = (yFlag & CFLAG_CHECK) == CFLAG_CHECK ? true : false;
|
||||||
|
bBFlag = (yFlag & BFLAG_SET) == BFLAG_SET ? true : false;
|
||||||
|
iMetricVal = tempCb.readInt();
|
||||||
|
|
||||||
|
return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
//write Object header
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
int objLenIndex = metricObjHeader.write(cb);
|
||||||
|
|
||||||
|
if (objLenIndex <= 0) {
|
||||||
|
throw new PcepParseException("Error: ObjectLength is " + objLenIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
int iFlag = (bCFlag) ? CFLAG_SET : CFLAG_RESET;
|
||||||
|
int iTemp = iFlag << IFLAG_SHIFT_VALUE;
|
||||||
|
iFlag = (bBFlag) ? BFLAG_SET : BFLAG_RESET;
|
||||||
|
iTemp = iTemp | (iFlag << BTYPE_SHIFT_VALUE);
|
||||||
|
iTemp = iTemp | bType;
|
||||||
|
cb.writeInt(iTemp);
|
||||||
|
cb.writeInt(iMetricVal);
|
||||||
|
|
||||||
|
short hLength = (short) (cb.writerIndex() - objStartIndex);
|
||||||
|
cb.setShort(objLenIndex, hLength);
|
||||||
|
//will be helpful during print().
|
||||||
|
metricObjHeader.setObjLen(hLength);
|
||||||
|
return hLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP metric object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepMetricObject.Builder {
|
||||||
|
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
private PcepObjectHeader metricObjHeader;
|
||||||
|
private int iMetricVal;
|
||||||
|
private boolean bIsMetricValSet = false;
|
||||||
|
private byte yFlag; // 6-flags
|
||||||
|
private boolean bCFlag;
|
||||||
|
private boolean bBFlag;
|
||||||
|
private byte bType;
|
||||||
|
private boolean bIsbTypeSet = false;
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMetricObject build() throws PcepParseException {
|
||||||
|
|
||||||
|
PcepObjectHeader metricObjHeader = this.bIsHeaderSet ? this.metricObjHeader : DEFAULT_METRIC_OBJECT_HEADER;
|
||||||
|
|
||||||
|
if (!this.bIsMetricValSet) {
|
||||||
|
throw new PcepParseException(" Metric Value NOT Set while building PcepMetricObject.");
|
||||||
|
}
|
||||||
|
if (!this.bIsbTypeSet) {
|
||||||
|
throw new PcepParseException(" Type NOT Set while building PcepMetricObject.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
metricObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
metricObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getMetricObjHeader() {
|
||||||
|
return this.metricObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setMetricObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.metricObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricVal() {
|
||||||
|
return this.iMetricVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setMetricVal(int value) {
|
||||||
|
this.iMetricVal = value;
|
||||||
|
this.bIsMetricValSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getYFlag() {
|
||||||
|
return this.yFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setYFlag(byte value) {
|
||||||
|
this.yFlag = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getCFlag() {
|
||||||
|
return this.bCFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setCFlag(boolean value) {
|
||||||
|
this.bCFlag = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getBFlag() {
|
||||||
|
return this.bBFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setBFlag(boolean value) {
|
||||||
|
this.bBFlag = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getBType() {
|
||||||
|
return this.bType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setBType(byte value) {
|
||||||
|
this.bType = value;
|
||||||
|
this.bIsbTypeSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("METRIC OBJECT");
|
||||||
|
long lTemp = iMetricVal & 0xFFFFFFFF;
|
||||||
|
log.debug("iMetricVal: " + lTemp);
|
||||||
|
lTemp = (bBFlag) ? 1 : 0;
|
||||||
|
log.debug("B Flag: " + lTemp);
|
||||||
|
lTemp = (bCFlag) ? 1 : 0;
|
||||||
|
log.debug("C Flag: " + lTemp);
|
||||||
|
lTemp = bType & 0xFF;
|
||||||
|
log.debug("Type: " + lTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Metric value", iMetricVal)
|
||||||
|
.add("B flag", bBFlag)
|
||||||
|
.add("C flag", bCFlag)
|
||||||
|
.add("B-type", bType)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,180 @@
|
|||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepAttribute;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepEroObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMsgPath;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides PCEP Message PAth for update message.
|
||||||
|
* Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10.
|
||||||
|
*/
|
||||||
|
public class PcepMsgPathVer1 implements PcepMsgPath {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <path> ::= <ERO><attribute-list>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class);
|
||||||
|
//PcepEroObject
|
||||||
|
private PcepEroObject eroObj;
|
||||||
|
private boolean isEroObjectSet;
|
||||||
|
// PcepAttribute
|
||||||
|
private PcepAttribute attrList;
|
||||||
|
private boolean isAttributeListSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize objects.
|
||||||
|
*/
|
||||||
|
public PcepMsgPathVer1() {
|
||||||
|
eroObj = null;
|
||||||
|
attrList = null;
|
||||||
|
isEroObjectSet = false;
|
||||||
|
isAttributeListSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject getEroObject() {
|
||||||
|
return eroObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute getPcepAttribute() {
|
||||||
|
return attrList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEroObject(PcepEroObject eroObj) {
|
||||||
|
this.eroObj = eroObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPcepAttribute(PcepAttribute attrList) {
|
||||||
|
this.attrList = attrList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param eroObj pcep ero object
|
||||||
|
* @param attrList pcep attribute
|
||||||
|
*/
|
||||||
|
public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) {
|
||||||
|
this.eroObj = eroObj;
|
||||||
|
isEroObjectSet = true;
|
||||||
|
this.attrList = attrList;
|
||||||
|
if (attrList == null) {
|
||||||
|
isAttributeListSet = false;
|
||||||
|
} else {
|
||||||
|
isAttributeListSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
PcepEroObject eroObj;
|
||||||
|
PcepAttribute attrList;
|
||||||
|
|
||||||
|
eroObj = PcepEroObjectVer1.read(cb);
|
||||||
|
attrList = PcepAttributeVer1.read(cb);
|
||||||
|
|
||||||
|
return new PcepMsgPathVer1(eroObj, attrList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
int iLenStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
//write Object header
|
||||||
|
if (this.isEroObjectSet) {
|
||||||
|
this.eroObj.write(cb);
|
||||||
|
}
|
||||||
|
if (this.isAttributeListSet) {
|
||||||
|
attrList.write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builder class for PCEP Message path.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepMsgPath.Builder {
|
||||||
|
|
||||||
|
private boolean bIsEROObjectSet = false;
|
||||||
|
private boolean bIsPcepAttributeSet = false;
|
||||||
|
|
||||||
|
//PCEP ERO Object
|
||||||
|
private PcepEroObject eroObject;
|
||||||
|
//PCEP Attribute list
|
||||||
|
private PcepAttribute pcepAttribute;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMsgPath build() throws PcepParseException {
|
||||||
|
|
||||||
|
//PCEP ERO Object
|
||||||
|
PcepEroObject eroObject = null;
|
||||||
|
//PCEP Attribute list
|
||||||
|
PcepAttribute pcepAttribute = null;
|
||||||
|
|
||||||
|
if (!this.bIsEROObjectSet) {
|
||||||
|
throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath.");
|
||||||
|
} else {
|
||||||
|
eroObject = this.eroObject;
|
||||||
|
}
|
||||||
|
if (!this.bIsPcepAttributeSet) {
|
||||||
|
throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath.");
|
||||||
|
} else {
|
||||||
|
pcepAttribute = this.pcepAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepMsgPathVer1(eroObject, pcepAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepEroObject getEroObject() {
|
||||||
|
return this.eroObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepAttribute getPcepAttribute() {
|
||||||
|
return this.pcepAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setEroObject(PcepEroObject eroObject) {
|
||||||
|
this.eroObject = eroObject;
|
||||||
|
this.bIsEROObjectSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
|
||||||
|
this.pcepAttribute = pcepAttribute;
|
||||||
|
this.bIsPcepAttributeSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("PcepMsgPath");
|
||||||
|
eroObj.print();
|
||||||
|
attrList.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("ERO object", eroObj)
|
||||||
|
.add("Attribute list", attrList)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,403 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.onosproject.pcepio.types.PcepObjectHeader;
|
||||||
|
import org.onosproject.pcepio.types.PcepValueType;
|
||||||
|
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepSrpObjectVer1 implements PcepSrpObject {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ref : draft-ietf-pce-stateful-pce-10, section : 7.2
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Object-Class | OT |Res|P|I| Object Length (bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Flags |R|
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| SRP-ID-number |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
// Optional TLVs //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepSrpObjectVer1.class);
|
||||||
|
|
||||||
|
public static final byte SRP_OBJ_TYPE = 1;
|
||||||
|
public static final byte SRP_OBJ_CLASS = 33;
|
||||||
|
public static final byte SRP_OBJECT_VERSION = 1;
|
||||||
|
public static final short SRP_OBJ_MINIMUM_LENGTH = 12;
|
||||||
|
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
|
||||||
|
public static final boolean DEFAULT_RFLAG = false;
|
||||||
|
|
||||||
|
static final PcepObjectHeader DEFAULT_SRP_OBJECT_HEADER = new PcepObjectHeader(SRP_OBJ_CLASS, SRP_OBJ_TYPE,
|
||||||
|
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, SRP_OBJ_MINIMUM_LENGTH);
|
||||||
|
|
||||||
|
private PcepObjectHeader srpObjHeader;
|
||||||
|
private static int flags;
|
||||||
|
private boolean bRFlag;
|
||||||
|
private int srpId;
|
||||||
|
|
||||||
|
//Optional TLV
|
||||||
|
private LinkedList<PcepValueType> llOptionalTlv;
|
||||||
|
public static final byte BBIT_SET = 1;
|
||||||
|
public static final byte BBIT_RESET = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param srpObjHeader srp object header
|
||||||
|
* @param bRFlag R flag
|
||||||
|
* @param srpID srp Id
|
||||||
|
* @param llOptionalTlv list of optional tlv
|
||||||
|
*/
|
||||||
|
public PcepSrpObjectVer1(PcepObjectHeader srpObjHeader, boolean bRFlag, int srpID,
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
|
||||||
|
this.srpObjHeader = srpObjHeader;
|
||||||
|
this.bRFlag = bRFlag;
|
||||||
|
this.srpId = srpID;
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the SRP object header.
|
||||||
|
*
|
||||||
|
* @param obj srp object header
|
||||||
|
*/
|
||||||
|
public void setSrpObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.srpObjHeader = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSrpID(int srpID) {
|
||||||
|
this.srpId = srpID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRFlag(boolean bRFlag) {
|
||||||
|
this.bRFlag = bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SRP object header.
|
||||||
|
*
|
||||||
|
* @return srpObjHeader
|
||||||
|
*/
|
||||||
|
public PcepObjectHeader getSrpObjHeader() {
|
||||||
|
return this.srpObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSrpID() {
|
||||||
|
return this.srpId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getRFlag() {
|
||||||
|
return this.bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns instance of PCEP SRP object.
|
||||||
|
*
|
||||||
|
* @param cb of channel buffer.
|
||||||
|
* @return PCEP SRP object
|
||||||
|
* @throws PcepParseException when srp object is not received in channel buffer
|
||||||
|
*/
|
||||||
|
public static PcepSrpObject read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
log.debug("SrpObject::read");
|
||||||
|
PcepObjectHeader srpObjHeader;
|
||||||
|
boolean bRFlag;
|
||||||
|
|
||||||
|
int srpID;
|
||||||
|
int flags;
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
srpObjHeader = PcepObjectHeader.read(cb);
|
||||||
|
|
||||||
|
if (SRP_OBJ_CLASS != srpObjHeader.getObjClass()) {
|
||||||
|
throw new PcepParseException("SRP object expected. But received " + srpObjHeader.getObjClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
//take only SrpObject buffer.
|
||||||
|
ChannelBuffer tempCb = cb.readBytes(srpObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
|
||||||
|
flags = tempCb.readInt();
|
||||||
|
bRFlag = (0 < flags) ? true : false;
|
||||||
|
srpID = tempCb.readInt();
|
||||||
|
|
||||||
|
llOptionalTlv = parseOptionalTlv(tempCb);
|
||||||
|
|
||||||
|
return new PcepSrpObjectVer1(srpObjHeader, bRFlag, srpID, llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
int objStartIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
//write common header
|
||||||
|
int objLenIndex = srpObjHeader.write(cb);
|
||||||
|
|
||||||
|
//write Flags
|
||||||
|
byte bFlag;
|
||||||
|
|
||||||
|
bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET;
|
||||||
|
|
||||||
|
cb.writeInt(bFlag);
|
||||||
|
|
||||||
|
//write SrpId
|
||||||
|
cb.writeInt(srpId);
|
||||||
|
|
||||||
|
// Add optional TLV
|
||||||
|
if (!packOptionalTlv(cb)) {
|
||||||
|
throw new PcepParseException("Failed to write srp tlv to channel buffer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//now write SRP Object Length
|
||||||
|
cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
|
||||||
|
|
||||||
|
return cb.writerIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse Optional TLvs from the channel buffer.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return list of optional tlvs
|
||||||
|
* @throws PcepParseException when unsupported tlv is received in srp object
|
||||||
|
*/
|
||||||
|
public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) {
|
||||||
|
|
||||||
|
PcepValueType tlv;
|
||||||
|
short hType = cb.readShort();
|
||||||
|
short hLength = cb.readShort();
|
||||||
|
|
||||||
|
switch (hType) {
|
||||||
|
|
||||||
|
case SymbolicPathNameTlv.TYPE:
|
||||||
|
tlv = SymbolicPathNameTlv.read(cb, hLength);
|
||||||
|
cb.skipBytes(hLength);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("Unsupported TLV received in SRP Object.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the padding
|
||||||
|
int pad = hLength % 4;
|
||||||
|
if (0 < pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
if (pad <= cb.readableBytes()) {
|
||||||
|
cb.skipBytes(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
llOutOptionalTlv.add(tlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return llOutOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes optional tlvs to channel buffer.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return true if writing optional tlv to channel buffer is success.
|
||||||
|
*/
|
||||||
|
protected boolean packOptionalTlv(ChannelBuffer cb) {
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
PcepValueType tlv = listIterator.next();
|
||||||
|
|
||||||
|
if (null == tlv) {
|
||||||
|
log.debug("tlv is null from OptionalTlv list");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tlv.write(cb);
|
||||||
|
|
||||||
|
// need to take care of padding
|
||||||
|
int pad = tlv.getLength() % 4;
|
||||||
|
|
||||||
|
if (0 != pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; ++i) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builder class for PCEP srp Object.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepSrpObject.Builder {
|
||||||
|
private boolean bIsHeaderSet = false;
|
||||||
|
private boolean bIsSrpIdset = false;
|
||||||
|
private boolean bIsRFlagSet = false;
|
||||||
|
|
||||||
|
private PcepObjectHeader srpObjHeader;
|
||||||
|
private int srpId;
|
||||||
|
private boolean bRFlag;
|
||||||
|
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
|
||||||
|
|
||||||
|
private boolean bIsPFlagSet = false;
|
||||||
|
private boolean bPFlag;
|
||||||
|
|
||||||
|
private boolean bIsIFlagSet = false;
|
||||||
|
private boolean bIFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject build() throws PcepParseException {
|
||||||
|
PcepObjectHeader srpObjHeader = this.bIsHeaderSet ? this.srpObjHeader : DEFAULT_SRP_OBJECT_HEADER;
|
||||||
|
|
||||||
|
boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG;
|
||||||
|
|
||||||
|
if (!this.bIsSrpIdset) {
|
||||||
|
throw new PcepParseException("SrpID not set while building SRP Object.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsPFlagSet) {
|
||||||
|
srpObjHeader.setPFlag(bPFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsIFlagSet) {
|
||||||
|
srpObjHeader.setIFlag(bIFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepSrpObjectVer1(srpObjHeader, bRFlag, this.srpId, this.llOptionalTlv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepObjectHeader getSrpObjHeader() {
|
||||||
|
return this.srpObjHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSrpObjHeader(PcepObjectHeader obj) {
|
||||||
|
this.srpObjHeader = obj;
|
||||||
|
this.bIsHeaderSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSrpID() {
|
||||||
|
return this.srpId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSrpID(int srpID) {
|
||||||
|
this.srpId = srpID;
|
||||||
|
this.bIsSrpIdset = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getRFlag() {
|
||||||
|
return this.bRFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setRFlag(boolean bRFlag) {
|
||||||
|
this.bRFlag = bRFlag;
|
||||||
|
this.bIsRFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
|
||||||
|
this.llOptionalTlv = llOptionalTlv;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepValueType> getOptionalTlv() {
|
||||||
|
return this.llOptionalTlv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setPFlag(boolean value) {
|
||||||
|
this.bPFlag = value;
|
||||||
|
this.bIsPFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setIFlag(boolean value) {
|
||||||
|
this.bIFlag = value;
|
||||||
|
this.bIsIFlagSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("SRP OBJECT");
|
||||||
|
long lTemp = (bRFlag) ? 1 : 0;
|
||||||
|
log.debug("r Flag: " + lTemp);
|
||||||
|
log.debug("SrpID: " + srpId);
|
||||||
|
|
||||||
|
log.debug("OPTIONAL TLV");
|
||||||
|
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("R flag", bRFlag)
|
||||||
|
.add("SRP ID", srpId)
|
||||||
|
.add("Optional tlv list", llOptionalTlv)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,308 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageWriter;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMsgPath;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepType;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PCEP Update Message: A Path Computation LSP Update Request message
|
||||||
|
* (also referred to as PCUpd message) is a PCEP message sent by a PCE
|
||||||
|
* to a PCC to update attributes of an LSP.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PcepUpdateMsgVer1 implements PcepUpdateMsg {
|
||||||
|
|
||||||
|
// Pcep version: 1
|
||||||
|
|
||||||
|
/* The format of the PCUpd message is as follows:
|
||||||
|
* <PCUpd Message> ::= <Common Header>
|
||||||
|
* <update-request-list>
|
||||||
|
* Where:
|
||||||
|
* <update-request-list> ::= <update-request>[<update-request-list>]
|
||||||
|
* <update-request> ::= <SRP>
|
||||||
|
* <LSP>
|
||||||
|
* <path>
|
||||||
|
* Where:
|
||||||
|
* <path> ::= <ERO><attribute-list>
|
||||||
|
* Where:
|
||||||
|
* <attribute-list> is defined in [RFC5440] and extended by PCEP extensions.
|
||||||
|
* where:
|
||||||
|
* <attribute-list> ::=[<LSPA>]
|
||||||
|
* [<BANDWIDTH>]
|
||||||
|
* [<metric-list>]
|
||||||
|
* [<IRO>]
|
||||||
|
* <metric-list> ::=<METRIC>[<metric-list>]
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | Ver | Flags | Message-Type | Message-Length |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | |
|
||||||
|
* // UPDATE REQUEST LIST //
|
||||||
|
* | |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*
|
||||||
|
* Reference:Internet-Draft-PCEP Extensions-for-Stateful-PCE-10
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepUpdateMsgVer1.class);
|
||||||
|
|
||||||
|
public static final byte PACKET_VERSION = 1;
|
||||||
|
// UpdateMsgMinLength = SrpObjMinLentgh(12)+LspObjMinLength(8)+EroObjMinLength(12)+ CommonHeaderLength(4)
|
||||||
|
public static final short PACKET_MINIMUM_LENGTH = 36;
|
||||||
|
public static final PcepType MSG_TYPE = PcepType.UPDATE;
|
||||||
|
//Update Request List
|
||||||
|
private LinkedList<PcepUpdateRequest> llUpdateRequestList;
|
||||||
|
|
||||||
|
public static final PcepUpdateMsgVer1.Reader READER = new Reader();
|
||||||
|
|
||||||
|
//Reader reads UpdateMessage from the channel.
|
||||||
|
static class Reader implements PcepMessageReader<PcepUpdateMsg> {
|
||||||
|
|
||||||
|
LinkedList<PcepUpdateRequest> llUpdateRequestList;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Readable bytes is less than update message minimum length");
|
||||||
|
}
|
||||||
|
|
||||||
|
llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
|
||||||
|
|
||||||
|
// fixed value property version == 1
|
||||||
|
byte version = cb.readByte();
|
||||||
|
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
|
||||||
|
if (version != PACKET_VERSION) {
|
||||||
|
throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version);
|
||||||
|
}
|
||||||
|
// fixed value property type == 11
|
||||||
|
byte type = cb.readByte();
|
||||||
|
if (type != MSG_TYPE.getType()) {
|
||||||
|
throw new PcepParseException("Wrong type. Expected=PcepType.UPDATE(11), got=" + type);
|
||||||
|
}
|
||||||
|
short length = cb.readShort();
|
||||||
|
if (length < PACKET_MINIMUM_LENGTH) {
|
||||||
|
throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
|
||||||
|
+ length);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("reading update message of length " + length);
|
||||||
|
|
||||||
|
// parse Update Request list
|
||||||
|
if (!parseUpdateRequestList(cb)) {
|
||||||
|
throw new PcepParseException("parsing Update Request List Failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepUpdateMsgVer1(llUpdateRequestList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse update request list.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return true after parsing Update Request List
|
||||||
|
* @throws PcepParseException while parsing update request list from channel buffer
|
||||||
|
*/
|
||||||
|
public boolean parseUpdateRequestList(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
/* <update-request-list>
|
||||||
|
* Where:
|
||||||
|
* <update-request-list> ::= <update-request>[<update-request-list>]
|
||||||
|
* <update-request> ::= <SRP>
|
||||||
|
* <LSP>
|
||||||
|
* <path>
|
||||||
|
* Where:
|
||||||
|
* <path> ::= <ERO><attribute-list>
|
||||||
|
* Where:
|
||||||
|
* <attribute-list> is defined in [RFC5440] and extended by PCEP extensions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (0 < cb.readableBytes()) {
|
||||||
|
|
||||||
|
PcepUpdateRequest pceUpdateReq = new PcepUpdateRequestVer1();
|
||||||
|
|
||||||
|
//Read SRP Object and Store it.
|
||||||
|
PcepSrpObject srpObj;
|
||||||
|
srpObj = PcepSrpObjectVer1.read(cb);
|
||||||
|
pceUpdateReq.setSrpObject(srpObj);
|
||||||
|
|
||||||
|
//Read LSP object and Store it.
|
||||||
|
PcepLspObject lspObj;
|
||||||
|
lspObj = PcepLspObjectVer1.read(cb);
|
||||||
|
pceUpdateReq.setLspObject(lspObj);
|
||||||
|
|
||||||
|
// Read Msg Path and store it.
|
||||||
|
PcepMsgPath msgPath = new PcepMsgPathVer1().read(cb);
|
||||||
|
pceUpdateReq.setMsgPath(msgPath);
|
||||||
|
|
||||||
|
llUpdateRequestList.add(pceUpdateReq);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize llUpdateRequestList.
|
||||||
|
*
|
||||||
|
* @param llUpdateRequestList list of PcepUpdateRequest.
|
||||||
|
*/
|
||||||
|
PcepUpdateMsgVer1(LinkedList<PcepUpdateRequest> llUpdateRequestList) {
|
||||||
|
this.llUpdateRequestList = llUpdateRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builder class for PCPE update message.
|
||||||
|
*/
|
||||||
|
static class Builder implements PcepUpdateMsg.Builder {
|
||||||
|
|
||||||
|
// PCEP report message fields
|
||||||
|
LinkedList<PcepUpdateRequest> llUpdateRequestList;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return PcepType.UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepUpdateMsg build() {
|
||||||
|
return new PcepUpdateMsgVer1(this.llUpdateRequestList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepUpdateRequest> getUpdateRequestList() {
|
||||||
|
return this.llUpdateRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) {
|
||||||
|
this.llUpdateRequestList = llUpdateRequestList;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
WRITER.write(cb, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Writer WRITER = new Writer();
|
||||||
|
|
||||||
|
//Writer writes UpdateMessage to the channel buffer.
|
||||||
|
static class Writer implements PcepMessageWriter<PcepUpdateMsgVer1> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ChannelBuffer cb, PcepUpdateMsgVer1 message) throws PcepParseException {
|
||||||
|
|
||||||
|
int startIndex = cb.writerIndex();
|
||||||
|
// first 3 bits set to version
|
||||||
|
cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
|
||||||
|
// message type
|
||||||
|
cb.writeByte(MSG_TYPE.getType());
|
||||||
|
/* length is length of variable message, will be updated at the end
|
||||||
|
* Store the position of message
|
||||||
|
* length in buffer
|
||||||
|
*/
|
||||||
|
int msgLenIndex = cb.writerIndex();
|
||||||
|
|
||||||
|
cb.writeShort((short) 0);
|
||||||
|
ListIterator<PcepUpdateRequest> listIterator = message.llUpdateRequestList.listIterator();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
|
||||||
|
PcepUpdateRequest updateReq = listIterator.next();
|
||||||
|
|
||||||
|
//SRP object is mandatory
|
||||||
|
PcepSrpObject srpObj = updateReq.getSrpObject();
|
||||||
|
srpObj.write(cb);
|
||||||
|
|
||||||
|
//LSP object is mandatory
|
||||||
|
PcepLspObject lspObj = updateReq.getLspObject();
|
||||||
|
lspObj.write(cb);
|
||||||
|
|
||||||
|
//PATH object is mandatory
|
||||||
|
PcepMsgPath msgPath = updateReq.getMsgPath();
|
||||||
|
msgPath.write(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update message length field
|
||||||
|
int length = cb.writerIndex() - startIndex;
|
||||||
|
cb.setShort(msgLenIndex, (short) length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepType getType() {
|
||||||
|
return MSG_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LinkedList<PcepUpdateRequest> getUpdateRequestList() {
|
||||||
|
return this.llUpdateRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) {
|
||||||
|
this.llUpdateRequestList = llUpdateRequestList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("PCEP UPDATE MESSAGE");
|
||||||
|
ListIterator<PcepUpdateRequest> listIterator = llUpdateRequestList.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
listIterator.next().print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Update Request list", llUpdateRequestList)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,207 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.protocol.ver1;
|
||||||
|
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepLspObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMsgPath;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepSrpObject;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PCEP Update Request List.
|
||||||
|
*/
|
||||||
|
public class PcepUpdateRequestVer1 implements PcepUpdateRequest {
|
||||||
|
|
||||||
|
/* <update-request-list>
|
||||||
|
* Where:
|
||||||
|
* <update-request-list> ::= <update-request>[<update-request-list>]
|
||||||
|
* <update-request> ::= <SRP>
|
||||||
|
* <LSP>
|
||||||
|
* <path>
|
||||||
|
* Where:
|
||||||
|
* <path> ::= <ERO><attribute-list>
|
||||||
|
* Where:
|
||||||
|
* <attribute-list> is defined in [RFC5440] and extended by PCEP extensions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepUpdateRequestVer1.class);
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
private PcepSrpObject srpObject;
|
||||||
|
//PCEP LSP Object
|
||||||
|
private PcepLspObject lspObject;
|
||||||
|
//PCEP Message path
|
||||||
|
private PcepMsgPath msgPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public PcepUpdateRequestVer1() {
|
||||||
|
srpObject = null;
|
||||||
|
lspObject = null;
|
||||||
|
msgPath = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all member variables.
|
||||||
|
*
|
||||||
|
* @param srpObject srp object
|
||||||
|
* @param lspObject lsp object
|
||||||
|
* @param msgPath message path object
|
||||||
|
*/
|
||||||
|
public PcepUpdateRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepMsgPath msgPath) {
|
||||||
|
this.srpObject = srpObject;
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
this.msgPath = msgPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject getSrpObject() {
|
||||||
|
return srpObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject getLspObject() {
|
||||||
|
return lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMsgPath getMsgPath() {
|
||||||
|
return msgPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSrpObject(PcepSrpObject srpObject) {
|
||||||
|
this.srpObject = srpObject;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLspObject(PcepLspObject lspObject) {
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgPath(PcepMsgPath msgPath) {
|
||||||
|
this.msgPath = msgPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder class for PCEP update request.
|
||||||
|
*/
|
||||||
|
public static class Builder implements PcepUpdateRequest.Builder {
|
||||||
|
|
||||||
|
private boolean bIsSRPObjectSet = false;
|
||||||
|
private boolean bIsLSPObjectSet = false;
|
||||||
|
private boolean bIsPcepMsgPathSet = false;
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
private PcepSrpObject srpObject;
|
||||||
|
//PCEP LSP Object
|
||||||
|
private PcepLspObject lspObject;
|
||||||
|
//PCEP Attribute list
|
||||||
|
private PcepMsgPath msgPath;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepUpdateRequest build() throws PcepParseException {
|
||||||
|
|
||||||
|
//PCEP SRP Object
|
||||||
|
PcepSrpObject srpObject = null;
|
||||||
|
//PCEP LSP Object
|
||||||
|
PcepLspObject lspObject = null;
|
||||||
|
//PCEP Attribute list
|
||||||
|
PcepMsgPath msgPath = null;
|
||||||
|
|
||||||
|
if (!this.bIsSRPObjectSet) {
|
||||||
|
throw new PcepParseException(" SRP Object NOT Set while building PcepUpdateRequest.");
|
||||||
|
} else {
|
||||||
|
srpObject = this.srpObject;
|
||||||
|
}
|
||||||
|
if (!this.bIsLSPObjectSet) {
|
||||||
|
throw new PcepParseException(" LSP Object NOT Set while building PcepUpdateRequest.");
|
||||||
|
} else {
|
||||||
|
lspObject = this.lspObject;
|
||||||
|
}
|
||||||
|
if (!this.bIsPcepMsgPathSet) {
|
||||||
|
throw new PcepParseException(" Msg Path NOT Set while building PcepUpdateRequest.");
|
||||||
|
} else {
|
||||||
|
msgPath = this.msgPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PcepUpdateRequestVer1(srpObject, lspObject, msgPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepSrpObject getSrpObject() {
|
||||||
|
return this.srpObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepLspObject getLspObject() {
|
||||||
|
return this.lspObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepMsgPath getMsgPath() {
|
||||||
|
return this.msgPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setSrpObject(PcepSrpObject srpobj) {
|
||||||
|
this.srpObject = srpobj;
|
||||||
|
this.bIsSRPObjectSet = true;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setLspObject(PcepLspObject lspObject) {
|
||||||
|
this.lspObject = lspObject;
|
||||||
|
this.bIsLSPObjectSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder setMsgPath(PcepMsgPath msgPath) {
|
||||||
|
this.msgPath = msgPath;
|
||||||
|
this.bIsPcepMsgPathSet = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("UPDATE REQUEST");
|
||||||
|
srpObject.print();
|
||||||
|
lspObject.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("SRP Object", srpObject)
|
||||||
|
.add("LSP object", lspObject)
|
||||||
|
.add("message path object", msgPath)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides Autonomous System Tlv which contains opaque value (32 Bit AS Number).
|
||||||
|
*/
|
||||||
|
public class AutonomousSystemTlv implements PcepValueType {
|
||||||
|
|
||||||
|
/* Reference :RFC3209
|
||||||
|
* 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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type=[TBD10] | Length=4 |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| opaque value (32 Bit AS Number) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(AutonomousSystemTlv.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 100; //TODD:change this TBD10
|
||||||
|
public static final short LENGTH = 4;
|
||||||
|
|
||||||
|
private final int rawValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize Autonomous system tlv value.
|
||||||
|
*
|
||||||
|
* @param rawValue value of Autonomous system tlv
|
||||||
|
*/
|
||||||
|
public AutonomousSystemTlv(int rawValue) {
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create instance of AutonomousSystemTlv.
|
||||||
|
*
|
||||||
|
* @param raw opaque value ofc 32 Bit AS Number
|
||||||
|
* @return object of AutonomousSystemTlv
|
||||||
|
*/
|
||||||
|
public static AutonomousSystemTlv of(final int raw) {
|
||||||
|
return new AutonomousSystemTlv(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns opaque value of 32 Bit AS Number.
|
||||||
|
*
|
||||||
|
* @return int value of rawValue
|
||||||
|
*/
|
||||||
|
public int getInt() {
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof AutonomousSystemTlv) {
|
||||||
|
AutonomousSystemTlv other = (AutonomousSystemTlv) obj;
|
||||||
|
return Objects.equals(rawValue, other.rawValue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
c.writeInt(rawValue);
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of AutonomousSystemTlv.
|
||||||
|
*
|
||||||
|
* @param c type of channel buffer
|
||||||
|
* @return object of AutonomousSystemTlv
|
||||||
|
*/
|
||||||
|
public static AutonomousSystemTlv read(ChannelBuffer c) {
|
||||||
|
return AutonomousSystemTlv.of(c.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("AutonomousSystemTlv");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
log.debug("Value: " + rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("TYPE", TYPE)
|
||||||
|
.add("Length", LENGTH)
|
||||||
|
.add("value", rawValue)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,14 +10,17 @@ import org.onosproject.pcepio.protocol.PcepOpenObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provide the error object list with open object.
|
* Provide the error object list with open object.
|
||||||
*/
|
*/
|
||||||
public class ErrorObjListWithOpen {
|
public class ErrorObjListWithOpen {
|
||||||
//errorObjList is mandatory
|
//errorObjList is mandatory
|
||||||
LinkedList<PcepErrorObject> llerrorObjList;
|
private LinkedList<PcepErrorObject> llerrorObjList;
|
||||||
// openObject is optional
|
// openObject is optional
|
||||||
PcepOpenObject openObject;
|
private PcepOpenObject openObject;
|
||||||
// flag to check if open object is set or not
|
// flag to check if open object is set or not
|
||||||
public boolean isOpenObjectSet;
|
public boolean isOpenObjectSet;
|
||||||
protected static final Logger log = LoggerFactory.getLogger(ErrorObjListWithOpen.class);
|
protected static final Logger log = LoggerFactory.getLogger(ErrorObjListWithOpen.class);
|
||||||
@ -49,6 +52,11 @@ public class ErrorObjListWithOpen {
|
|||||||
isOpenObjectSet = false;
|
isOpenObjectSet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns error type.
|
||||||
|
*
|
||||||
|
* @return error type
|
||||||
|
*/
|
||||||
public LinkedList<Integer> getErrorType() {
|
public LinkedList<Integer> getErrorType() {
|
||||||
LinkedList<Integer> errorType = new LinkedList<Integer>();
|
LinkedList<Integer> errorType = new LinkedList<Integer>();
|
||||||
if (llerrorObjList != null) {
|
if (llerrorObjList != null) {
|
||||||
@ -64,6 +72,11 @@ public class ErrorObjListWithOpen {
|
|||||||
return errorType;
|
return errorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns error value.
|
||||||
|
*
|
||||||
|
* @return error value
|
||||||
|
*/
|
||||||
public LinkedList<Integer> getErrorValue() {
|
public LinkedList<Integer> getErrorValue() {
|
||||||
LinkedList<Integer> errorValue = new LinkedList<Integer>();
|
LinkedList<Integer> errorValue = new LinkedList<Integer>();
|
||||||
if (llerrorObjList != null) {
|
if (llerrorObjList != null) {
|
||||||
@ -79,7 +92,8 @@ public class ErrorObjListWithOpen {
|
|||||||
}
|
}
|
||||||
return errorValue;
|
return errorValue;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
/**
|
||||||
* Checks whether error object list is empty or not.
|
* Checks whether error object list is empty or not.
|
||||||
*
|
*
|
||||||
* @return whether error object list is empty or not
|
* @return whether error object list is empty or not
|
||||||
@ -90,7 +104,7 @@ public class ErrorObjListWithOpen {
|
|||||||
return (!this.llerrorObjList.isEmpty()) ? true : false;
|
return (!this.llerrorObjList.isEmpty()) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Write Error Object List and Open Object to channel buffer.
|
* Write Error Object List and Open Object to channel buffer.
|
||||||
*
|
*
|
||||||
* @param bb of type channel buffer
|
* @param bb of type channel buffer
|
||||||
@ -121,7 +135,7 @@ public class ErrorObjListWithOpen {
|
|||||||
return bb.writerIndex() - iLenStartIndex;
|
return bb.writerIndex() - iLenStartIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Prints the attributes of ErrorObject List with open Object.
|
* Prints the attributes of ErrorObject List with open Object.
|
||||||
*/
|
*/
|
||||||
public void print() {
|
public void print() {
|
||||||
@ -137,4 +151,19 @@ public class ErrorObjListWithOpen {
|
|||||||
openObject.print();
|
openObject.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
|
||||||
|
|
||||||
|
if (openObject == null) {
|
||||||
|
toStrHelper
|
||||||
|
.add("error Obj List", llerrorObjList);
|
||||||
|
} else {
|
||||||
|
toStrHelper
|
||||||
|
.add("error Obj List", llerrorObjList)
|
||||||
|
.add("open Object", openObject);
|
||||||
|
}
|
||||||
|
return toStrHelper.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author b00295750
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides IPv4 Sub Object.
|
||||||
|
*/
|
||||||
|
public class IPv4SubObject implements PcepValueType {
|
||||||
|
|
||||||
|
/*Reference : RFC 4874:3.1.1
|
||||||
|
* 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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | IPv4 address (4 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv4 address (continued) | Prefix Length | Resvd |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(IPv4SubObject.class);
|
||||||
|
|
||||||
|
public static final byte TYPE = 0x01;
|
||||||
|
public static final byte LENGTH = 8;
|
||||||
|
public static final byte VALUE_LENGTH = 6;
|
||||||
|
public static final byte OBJ_LENGTH = 8;
|
||||||
|
public static final byte LBIT = 0;
|
||||||
|
public static final int SHIFT_LBIT_POSITION = 7;
|
||||||
|
private int ipAddress;
|
||||||
|
private byte prefixLen;
|
||||||
|
private byte resvd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize ipv4 address.
|
||||||
|
*
|
||||||
|
* @param ipAddr ipv4 address
|
||||||
|
*/
|
||||||
|
public IPv4SubObject(int ipAddr) {
|
||||||
|
this.ipAddress = ipAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize ipAddress, prefixLen and resvd.
|
||||||
|
*
|
||||||
|
* @param ipAddress ipv4 address
|
||||||
|
* @param prefixLen prefix length
|
||||||
|
* @param resvd reserved flags value
|
||||||
|
*/
|
||||||
|
public IPv4SubObject(int ipAddress, byte prefixLen, byte resvd) {
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
this.prefixLen = prefixLen;
|
||||||
|
this.resvd = resvd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new instance of IPv4SubObject.
|
||||||
|
*
|
||||||
|
* @param ipAddress ipv4 address
|
||||||
|
* @param prefixLen prefix length
|
||||||
|
* @param resvd reserved flags value
|
||||||
|
* @return object of IPv4SubObject
|
||||||
|
*/
|
||||||
|
public static IPv4SubObject of(int ipAddress, byte prefixLen, byte resvd) {
|
||||||
|
return new IPv4SubObject(ipAddress, prefixLen, resvd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns prefixLen of IPv4 IP address.
|
||||||
|
*
|
||||||
|
* @return byte value of rawValue
|
||||||
|
*/
|
||||||
|
public byte getPrefixLen() {
|
||||||
|
return prefixLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns value of IPv4 IP address.
|
||||||
|
*
|
||||||
|
* @return int value of ipv4 address
|
||||||
|
*/
|
||||||
|
public int getIpAddress() {
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(ipAddress, prefixLen, resvd);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof IPv4SubObject) {
|
||||||
|
IPv4SubObject other = (IPv4SubObject) obj;
|
||||||
|
return Objects.equals(this.ipAddress, other.ipAddress) && Objects.equals(this.prefixLen, other.prefixLen)
|
||||||
|
&& Objects.equals(this.resvd, other.resvd);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of IPv4SubObject.
|
||||||
|
*
|
||||||
|
* @param c type of channel buffer
|
||||||
|
* @return object of IPv4SubObject
|
||||||
|
*/
|
||||||
|
public static PcepValueType read(ChannelBuffer c) {
|
||||||
|
int ipAddess = c.readInt();
|
||||||
|
byte prefixLen = c.readByte();
|
||||||
|
byte resvd = c.readByte();
|
||||||
|
return new IPv4SubObject(ipAddess, prefixLen, resvd);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
byte bValue = LBIT;
|
||||||
|
bValue = (byte) (bValue << SHIFT_LBIT_POSITION);
|
||||||
|
bValue = (byte) (bValue | TYPE);
|
||||||
|
c.writeByte(bValue);
|
||||||
|
c.writeByte(OBJ_LENGTH);
|
||||||
|
c.writeInt(ipAddress);
|
||||||
|
c.writeByte(prefixLen);
|
||||||
|
c.writeByte(resvd);
|
||||||
|
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("IPv4SubObject");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
log.debug("IPv4 address: " + String.format("%08X", ipAddress));
|
||||||
|
log.debug("Prefix Length: " + prefixLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Type", TYPE)
|
||||||
|
.add("Length", LENGTH)
|
||||||
|
.add("IPv4 Address", ipAddress)
|
||||||
|
.add("Prefix Length", prefixLen)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,228 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides IPv6 Sub Object.
|
||||||
|
*/
|
||||||
|
public class IPv6SubObject implements PcepValueType {
|
||||||
|
|
||||||
|
/* reference :RFC 4874.
|
||||||
|
Subobject : IPv6 address
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type | Length | IPv6 address (16 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv6 address (continued) | Prefix Length | Flags |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
Type
|
||||||
|
|
||||||
|
0x02 IPv6 address
|
||||||
|
|
||||||
|
Length
|
||||||
|
|
||||||
|
The Length contains the total length of the subobject in bytes,
|
||||||
|
including the Type and Length fields. The Length is always 20.
|
||||||
|
|
||||||
|
IPv6 address
|
||||||
|
|
||||||
|
A 128-bit unicast host address.
|
||||||
|
|
||||||
|
Prefix length
|
||||||
|
|
||||||
|
128
|
||||||
|
|
||||||
|
Flags
|
||||||
|
|
||||||
|
0x01 Local protection available
|
||||||
|
|
||||||
|
Indicates that the link downstream of this node is
|
||||||
|
protected via a local repair mechanism. This flag can
|
||||||
|
only be set if the Local protection flag was set in the
|
||||||
|
SESSION_ATTRIBUTE object of the corresponding Path
|
||||||
|
message.
|
||||||
|
|
||||||
|
0x02 Local protection in use
|
||||||
|
|
||||||
|
Indicates that a local repair mechanism is in use to
|
||||||
|
maintain this tunnel (usually in the face of an outage
|
||||||
|
of the link it was previously routed over).
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(IPv6SubObject.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 0x02;
|
||||||
|
public static final short LENGTH = 20;
|
||||||
|
public static final byte VALUE_LENGTH = 18;
|
||||||
|
|
||||||
|
private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
public static final IPv6SubObject NONE = new IPv6SubObject(NONE_VAL);
|
||||||
|
|
||||||
|
private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
|
||||||
|
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
|
||||||
|
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
|
||||||
|
public static final IPv6SubObject NO_MASK = new IPv6SubObject(NO_MASK_VAL);
|
||||||
|
public static final IPv6SubObject FULL_MASK = NONE;
|
||||||
|
|
||||||
|
private final byte[] rawValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor to initialize rawValue with ipv6 address.
|
||||||
|
*
|
||||||
|
* @param rawValue ipv6 address
|
||||||
|
*/
|
||||||
|
public IPv6SubObject(byte[] rawValue) {
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create instance of IPv6SubObject.
|
||||||
|
*
|
||||||
|
* @param raw byte array of ipv6 address
|
||||||
|
* @return object of IPv6SubObject
|
||||||
|
*/
|
||||||
|
public static IPv6SubObject of(final byte[] raw) {
|
||||||
|
//check NONE_VAL
|
||||||
|
boolean bFoundNONE = true;
|
||||||
|
//value starts from 3rd byte.
|
||||||
|
for (int i = 2; i < 20; ++i) {
|
||||||
|
if (NONE_VAL[i] != raw[i]) {
|
||||||
|
bFoundNONE = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bFoundNONE) {
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check NO_MASK_VAL
|
||||||
|
boolean bFoundNoMask = true;
|
||||||
|
//value starts from 3rd byte.
|
||||||
|
for (int i = 2; i < 20; ++i) {
|
||||||
|
if (0xFF != raw[i]) {
|
||||||
|
bFoundNoMask = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bFoundNoMask) {
|
||||||
|
return NO_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new IPv6SubObject(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns value of IPv6 Sub Object.
|
||||||
|
*
|
||||||
|
* @return byte array of ipv6 address
|
||||||
|
*/
|
||||||
|
public byte[] getValue() {
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof IPv6SubObject) {
|
||||||
|
IPv6SubObject other = (IPv6SubObject) obj;
|
||||||
|
return Objects.equals(rawValue, other.rawValue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
c.writeBytes(rawValue);
|
||||||
|
return c.writerIndex() - iStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of IPv6SubObject.
|
||||||
|
*
|
||||||
|
* @param c type of channel buffer
|
||||||
|
* @return object of IPv6SubObject
|
||||||
|
*/
|
||||||
|
public static IPv6SubObject read20Bytes(ChannelBuffer c) {
|
||||||
|
byte[] yTemp = new byte[20];
|
||||||
|
c.readBytes(yTemp, 0, 20);
|
||||||
|
return IPv6SubObject.of(yTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("IPv6SubObject");
|
||||||
|
log.debug("Type: ", TYPE);
|
||||||
|
log.debug("Length: ", LENGTH);
|
||||||
|
if (null != rawValue) {
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
for (byte b : rawValue) {
|
||||||
|
result.append(String.format("%02X ", b));
|
||||||
|
}
|
||||||
|
log.debug(result.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Type", TYPE)
|
||||||
|
.add("Length", LENGTH)
|
||||||
|
.add("IPv6 Address", rawValue)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path Key SubObject: When a PCC needs to expand a path-key in order to expand a CPS, it
|
||||||
|
* issues a Path Computation Request (PCReq) to the PCE identified in
|
||||||
|
* the PKS in the RSVP-TE ERO that it is processing. The PCC supplies
|
||||||
|
* the PKS to be expanded in a PATH-KEY SubObject in the PCReq message.
|
||||||
|
*/
|
||||||
|
public class PathKeySubObject implements PcepValueType {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pathkey subobject(RFC 5520):
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | Path-Key |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| PCE ID (4 bytes) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PathKeySubObject.class);
|
||||||
|
|
||||||
|
public static final byte TYPE = 0x40;
|
||||||
|
public static final byte LENGTH = 8;
|
||||||
|
private final short pathKey;
|
||||||
|
private final int pceID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Path Key sub Object which initializes pathKey and pceId.
|
||||||
|
*
|
||||||
|
* @param pathKey path key provided by PCC
|
||||||
|
* @param pceID ID for the PCE
|
||||||
|
*/
|
||||||
|
public PathKeySubObject(short pathKey, int pceID) {
|
||||||
|
this.pathKey = pathKey;
|
||||||
|
this.pceID = pceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Path Key sub Object which initializes pathKey and pceId.
|
||||||
|
*
|
||||||
|
* @param pathKey path key provided by PCC
|
||||||
|
* @param pceID PCE id
|
||||||
|
* @return new object of type path key sub object
|
||||||
|
*/
|
||||||
|
public static PathKeySubObject of(short pathKey, int pceID) {
|
||||||
|
return new PathKeySubObject(pathKey, pceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Path Key.
|
||||||
|
*
|
||||||
|
* @return pathKey
|
||||||
|
*/
|
||||||
|
public short getPathKey() {
|
||||||
|
return pathKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pceID.
|
||||||
|
*
|
||||||
|
* @return pceID
|
||||||
|
*/
|
||||||
|
public int getPceId() {
|
||||||
|
return pceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(pathKey, pceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PathKeySubObject) {
|
||||||
|
PathKeySubObject other = (PathKeySubObject) obj;
|
||||||
|
return Objects.equals(this.pathKey, other.pathKey) && Objects.equals(this.pceID, other.pceID);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
|
||||||
|
c.writeShort(pathKey);
|
||||||
|
c.writeInt(pceID);
|
||||||
|
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns new path key sub objects.
|
||||||
|
*
|
||||||
|
* @param c of type channel buffer
|
||||||
|
* @return object of type path key sub object
|
||||||
|
*/
|
||||||
|
public static PcepValueType read(ChannelBuffer c) {
|
||||||
|
Short pathKey = c.readShort();
|
||||||
|
int pceID = c.readInt();
|
||||||
|
return new PathKeySubObject(pathKey, pceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("PathKeySubObject");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
log.debug("Path Key: " + pathKey);
|
||||||
|
log.debug("PCEID: " + pceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Type", TYPE).add("Length", LENGTH)
|
||||||
|
.add("Path Key", pathKey)
|
||||||
|
.add("PCE ID", pceID)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provide the PCEP Error Info Details.
|
||||||
|
*/
|
||||||
|
public final class PcepErrorDetailInfo {
|
||||||
|
|
||||||
|
private PcepErrorDetailInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error Types
|
||||||
|
/**
|
||||||
|
Error- Meaning Reference:RFC 5440
|
||||||
|
Type
|
||||||
|
1 PCEP session establishment failure
|
||||||
|
Error-value=1: reception of an invalid Open message or a non Open message.
|
||||||
|
Error-value=2: no Open message received before the expiration of the OpenWait timer
|
||||||
|
Error-value=3: unacceptable and non-negotiable session characteristics
|
||||||
|
Error-value=4: unacceptable but negotiable session characteristics
|
||||||
|
Error-value=5: reception of a second Open message with still unacceptable session characteristics
|
||||||
|
Error-value=6: reception of a PCErr message proposing unacceptable session characteristics
|
||||||
|
Error-value=7: No Keepalive or PCErr message received before the expiration of the KeepWait timer
|
||||||
|
Error-value=8: PCEP version not supported
|
||||||
|
2 Capability not supported
|
||||||
|
3 Unknown Object
|
||||||
|
Error-value=1: Unrecognized object class
|
||||||
|
Error-value=2: Unrecognized object Type
|
||||||
|
4 Not supported object
|
||||||
|
Error-value=1: Not supported object class
|
||||||
|
Error-value=2: Not supported object Type
|
||||||
|
5 Policy violation
|
||||||
|
Error-value=1: C bit of the METRIC object set (request rejected)
|
||||||
|
Error-value=2: O bit of the RP object cleared (request rejected)
|
||||||
|
6 Mandatory Object missing
|
||||||
|
Error-value=1: RP object missing
|
||||||
|
Error-value=2: RRO missing for a re-optimization request (R bit of the RP object set)
|
||||||
|
Error-value=3: END-POINTS object missing
|
||||||
|
7 Synchronized path computation request missing
|
||||||
|
8 Unknown request reference
|
||||||
|
9 Attempt to establish a second PCEP session
|
||||||
|
10 Reception of an invalid object
|
||||||
|
Error-value=1: reception of an object with P flag not set although the P flag must be
|
||||||
|
set according to this specification.
|
||||||
|
*/
|
||||||
|
public static final byte ERROR_TYPE_1 = 1;
|
||||||
|
public static final byte ERROR_TYPE_2 = 2;
|
||||||
|
public static final byte ERROR_TYPE_3 = 3;
|
||||||
|
public static final byte ERROR_TYPE_4 = 4;
|
||||||
|
public static final byte ERROR_TYPE_5 = 5;
|
||||||
|
public static final byte ERROR_TYPE_6 = 6;
|
||||||
|
public static final byte ERROR_TYPE_7 = 7;
|
||||||
|
public static final byte ERROR_TYPE_8 = 8;
|
||||||
|
public static final byte ERROR_TYPE_9 = 9;
|
||||||
|
public static final byte ERROR_TYPE_10 = 10;
|
||||||
|
|
||||||
|
// Error Values
|
||||||
|
public static final byte ERROR_VALUE_1 = 1;
|
||||||
|
public static final byte ERROR_VALUE_2 = 2;
|
||||||
|
public static final byte ERROR_VALUE_3 = 3;
|
||||||
|
public static final byte ERROR_VALUE_4 = 4;
|
||||||
|
public static final byte ERROR_VALUE_5 = 5;
|
||||||
|
public static final byte ERROR_VALUE_6 = 6;
|
||||||
|
public static final byte ERROR_VALUE_7 = 7;
|
||||||
|
public static final byte ERROR_VALUE_8 = 8;
|
||||||
|
public static final byte ERROR_VALUE_9 = 9;
|
||||||
|
public static final byte ERROR_VALUE_10 = 10;
|
||||||
|
}
|
||||||
@ -9,7 +9,9 @@ import org.onosproject.pcepio.protocol.PcepSrpObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/*
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
* Provides Pcep Label.
|
* Provides Pcep Label.
|
||||||
* REference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
|
* REference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
|
||||||
*/
|
*/
|
||||||
@ -18,13 +20,13 @@ public class PcepLabelDownload {
|
|||||||
protected static final Logger log = LoggerFactory.getLogger(PcepLabelDownload.class);
|
protected static final Logger log = LoggerFactory.getLogger(PcepLabelDownload.class);
|
||||||
|
|
||||||
//PCEP SPR Object
|
//PCEP SPR Object
|
||||||
PcepSrpObject srpObject;
|
private PcepSrpObject srpObject;
|
||||||
//PCEP LSP Object
|
//PCEP LSP Object
|
||||||
PcepLspObject lspObject;
|
private PcepLspObject lspObject;
|
||||||
//LinkList of Labels
|
//LinkList of Labels
|
||||||
LinkedList<PcepLabelObject> llLabelList;
|
private LinkedList<PcepLabelObject> llLabelList;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns SRP Object.
|
* Returns SRP Object.
|
||||||
*
|
*
|
||||||
* @return PCEP SRP Object
|
* @return PCEP SRP Object
|
||||||
@ -33,7 +35,7 @@ public class PcepLabelDownload {
|
|||||||
return srpObject;
|
return srpObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Sets the Pcep Srp Object.
|
* Sets the Pcep Srp Object.
|
||||||
*
|
*
|
||||||
* @param srpobj PCEP SRP Object
|
* @param srpobj PCEP SRP Object
|
||||||
@ -42,7 +44,7 @@ public class PcepLabelDownload {
|
|||||||
this.srpObject = srpobj;
|
this.srpObject = srpobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns LSP Object.
|
* Returns LSP Object.
|
||||||
*
|
*
|
||||||
* @return PCEP LSP Object
|
* @return PCEP LSP Object
|
||||||
@ -51,7 +53,7 @@ public class PcepLabelDownload {
|
|||||||
return lspObject;
|
return lspObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Sets the Pcep LSP Object.
|
* Sets the Pcep LSP Object.
|
||||||
*
|
*
|
||||||
* @param lspObject PCEP LSP Object
|
* @param lspObject PCEP LSP Object
|
||||||
@ -60,7 +62,7 @@ public class PcepLabelDownload {
|
|||||||
this.lspObject = lspObject;
|
this.lspObject = lspObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns a list of labels.
|
* Returns a list of labels.
|
||||||
*
|
*
|
||||||
* @return llLabelList list of pcep label objects
|
* @return llLabelList list of pcep label objects
|
||||||
@ -69,7 +71,7 @@ public class PcepLabelDownload {
|
|||||||
return llLabelList;
|
return llLabelList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* set the llLabelList list of type PcepLableObject.
|
* set the llLabelList list of type PcepLableObject.
|
||||||
*
|
*
|
||||||
* @param llLabelList list of pcep label objects
|
* @param llLabelList list of pcep label objects
|
||||||
@ -78,7 +80,7 @@ public class PcepLabelDownload {
|
|||||||
this.llLabelList = llLabelList;
|
this.llLabelList = llLabelList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Prints the attribute of PcepLableObject.
|
* Prints the attribute of PcepLableObject.
|
||||||
*/
|
*/
|
||||||
public void print() {
|
public void print() {
|
||||||
@ -92,4 +94,13 @@ public class PcepLabelDownload {
|
|||||||
listIterator.next().print();
|
listIterator.next().print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("SRP object", srpObject)
|
||||||
|
.add("LSP object", lspObject)
|
||||||
|
.add("label object list", llLabelList)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ import org.onosproject.pcepio.protocol.PcepSrpObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide PCEP Label Map.
|
* Provide PCEP Label Map.
|
||||||
* Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
|
* Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
|
||||||
@ -30,11 +32,11 @@ public class PcepLabelMap {
|
|||||||
|
|
||||||
protected static final Logger log = LoggerFactory.getLogger(PcepLabelMap.class);
|
protected static final Logger log = LoggerFactory.getLogger(PcepLabelMap.class);
|
||||||
//PCEP SRP Object
|
//PCEP SRP Object
|
||||||
PcepSrpObject srpObject;
|
private PcepSrpObject srpObject;
|
||||||
//PCEP Label Object
|
//PCEP Label Object
|
||||||
PcepLabelObject labelObject;
|
private PcepLabelObject labelObject;
|
||||||
//PCEP FEC Object
|
//PCEP FEC Object
|
||||||
PcepFecObject fecObject;
|
private PcepFecObject fecObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Fec Object.
|
* Sets Fec Object.
|
||||||
@ -99,4 +101,13 @@ public class PcepLabelMap {
|
|||||||
labelObject.print();
|
labelObject.print();
|
||||||
fecObject.print();
|
fecObject.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("SRP object", srpObject)
|
||||||
|
.add("Label object", labelObject)
|
||||||
|
.add("Fec object", fecObject)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepNaiIpv4Adjacency implements PcepNai {
|
||||||
|
|
||||||
|
public static final byte ST_TYPE = 0x03;
|
||||||
|
private final int localIpv4Addr;
|
||||||
|
private final int remoteIpv4Addr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize variables.
|
||||||
|
*
|
||||||
|
* @param localIpv4 local ipv4 address
|
||||||
|
* @param remoteIpv4 remote ipv4 address
|
||||||
|
*/
|
||||||
|
public PcepNaiIpv4Adjacency(int localIpv4, int remoteIpv4) {
|
||||||
|
this.localIpv4Addr = localIpv4;
|
||||||
|
this.remoteIpv4Addr = remoteIpv4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getType() {
|
||||||
|
return ST_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer bb) {
|
||||||
|
int iLenStartIndex = bb.writerIndex();
|
||||||
|
bb.writeInt(localIpv4Addr);
|
||||||
|
bb.writeInt(remoteIpv4Addr);
|
||||||
|
return bb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of PcepNAIIpv4AdjacencyVer1.
|
||||||
|
*
|
||||||
|
* @param cb of channel buffer
|
||||||
|
* @return object of PcepNAIIpv4Adjacency
|
||||||
|
*/
|
||||||
|
public static PcepNaiIpv4Adjacency read(ChannelBuffer cb) {
|
||||||
|
int localIpv4 = cb.readInt();
|
||||||
|
int remoteIpv4 = cb.readInt();
|
||||||
|
return new PcepNaiIpv4Adjacency(localIpv4, remoteIpv4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(localIpv4Addr, remoteIpv4Addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PcepNaiIpv4Adjacency) {
|
||||||
|
PcepNaiIpv4Adjacency other = (PcepNaiIpv4Adjacency) obj;
|
||||||
|
return Objects.equals(this.localIpv4Addr, other.localIpv4Addr)
|
||||||
|
&& Objects.equals(this.remoteIpv4Addr, other.remoteIpv4Addr);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("local IPv4 Address", localIpv4Addr)
|
||||||
|
.add("remote IPv4 Address", remoteIpv4Addr)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepNaiIpv4NodeId implements PcepNai {
|
||||||
|
|
||||||
|
public static final byte ST_TYPE = 0x01;
|
||||||
|
|
||||||
|
private final int ipv4NodeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize ipv4NodeId.
|
||||||
|
*
|
||||||
|
* @param value ipv4 node id
|
||||||
|
*/
|
||||||
|
public PcepNaiIpv4NodeId(int value) {
|
||||||
|
this.ipv4NodeId = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an object of PcepNaiIpv4NodeId.
|
||||||
|
*
|
||||||
|
* @param value ipv4 node id
|
||||||
|
* @return object of PcepNaiIpv4NodeId
|
||||||
|
*/
|
||||||
|
public static PcepNaiIpv4NodeId of(int value) {
|
||||||
|
return new PcepNaiIpv4NodeId(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getType() {
|
||||||
|
return ST_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer bb) {
|
||||||
|
int iLenStartIndex = bb.writerIndex();
|
||||||
|
bb.writeInt(ipv4NodeId);
|
||||||
|
return bb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1.
|
||||||
|
*
|
||||||
|
* @param bb of channel buffer.
|
||||||
|
* @return object of PcepNAIIpv4NodeIdVer1
|
||||||
|
*/
|
||||||
|
public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
|
||||||
|
return new PcepNaiIpv4NodeId(bb.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(ipv4NodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PcepNaiIpv4NodeId) {
|
||||||
|
PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj;
|
||||||
|
return Objects.equals(this.ipv4NodeId, other.ipv4NodeId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("IPv4 Node Id", ipv4NodeId)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepNaiIpv6Adjacency implements PcepNai {
|
||||||
|
|
||||||
|
public static final byte ST_TYPE = 0x04;
|
||||||
|
public static final byte IPV6_LEN = 0x10;
|
||||||
|
|
||||||
|
private final byte[] localIpv6Addr;
|
||||||
|
private final byte[] remoteIpv6Addr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize local ipv6 and remote ipv6.
|
||||||
|
*
|
||||||
|
* @param localIpv6 local ipv6 address
|
||||||
|
* @param remoteIpv6 remote ipv6 address
|
||||||
|
*/
|
||||||
|
public PcepNaiIpv6Adjacency(byte[] localIpv6, byte[] remoteIpv6) {
|
||||||
|
this.localIpv6Addr = localIpv6;
|
||||||
|
this.remoteIpv6Addr = remoteIpv6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getType() {
|
||||||
|
return ST_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer bb) {
|
||||||
|
int iLenStartIndex = bb.writerIndex();
|
||||||
|
bb.writeBytes(localIpv6Addr);
|
||||||
|
bb.writeBytes(remoteIpv6Addr);
|
||||||
|
return bb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and returns object of PcepNAIIpv6AdjacencyVer1.
|
||||||
|
*
|
||||||
|
* @param bb of type channel buffer
|
||||||
|
* @return object of PcepNAIIpv6AdjacencyVer1
|
||||||
|
*/
|
||||||
|
public static PcepNaiIpv6Adjacency read(ChannelBuffer bb) {
|
||||||
|
byte[] localIpv6 = new byte[IPV6_LEN];
|
||||||
|
bb.readBytes(localIpv6, 0, IPV6_LEN);
|
||||||
|
byte[] remoteIpv6 = new byte[IPV6_LEN];
|
||||||
|
bb.readBytes(remoteIpv6, 0, IPV6_LEN);
|
||||||
|
return new PcepNaiIpv6Adjacency(localIpv6, remoteIpv6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(localIpv6Addr, remoteIpv6Addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PcepNaiIpv6Adjacency) {
|
||||||
|
PcepNaiIpv6Adjacency other = (PcepNaiIpv6Adjacency) obj;
|
||||||
|
return Objects.equals(this.localIpv6Addr, other.localIpv6Addr)
|
||||||
|
&& Objects.equals(this.remoteIpv6Addr, other.remoteIpv6Addr);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates object of PcepNaiIpv6Adjacency with local ipv6 address and remote ipv6 address.
|
||||||
|
*
|
||||||
|
* @param localIpv6Addr local ipv6 address
|
||||||
|
* @param remoteIpv6Addr remote ipv6 address
|
||||||
|
* @return object of PcepNaiIpv6Adjacency
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static PcepNaiIpv6Adjacency of(final byte[] localIpv6Addr, final byte[] remoteIpv6Addr) {
|
||||||
|
return new PcepNaiIpv6Adjacency(localIpv6Addr, remoteIpv6Addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("local IPV6 address", localIpv6Addr)
|
||||||
|
.add("remote IPV6 address", remoteIpv6Addr)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepNaiIpv6NodeId implements PcepNai {
|
||||||
|
|
||||||
|
public static final byte ST_TYPE = 0x02;
|
||||||
|
public static final byte IPV6_LEN = 0x10;
|
||||||
|
|
||||||
|
private final byte[] ipv6NodeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize ipv6NodeId.
|
||||||
|
*
|
||||||
|
* @param value ipv6 node id
|
||||||
|
*/
|
||||||
|
public PcepNaiIpv6NodeId(byte[] value) {
|
||||||
|
this.ipv6NodeId = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getType() {
|
||||||
|
return ST_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) {
|
||||||
|
int iLenStartIndex = cb.writerIndex();
|
||||||
|
cb.writeBytes(ipv6NodeId);
|
||||||
|
return cb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from the channel buffer and returns object of PcepNAIIpv6NodeId.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer.
|
||||||
|
* @return object of PcepNAIIpv6NodeId
|
||||||
|
*/
|
||||||
|
public static PcepNaiIpv6NodeId read(ChannelBuffer cb) {
|
||||||
|
byte[] ipv6NodeId = new byte[IPV6_LEN];
|
||||||
|
cb.readBytes(ipv6NodeId, 0, IPV6_LEN);
|
||||||
|
return new PcepNaiIpv6NodeId(ipv6NodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(ipv6NodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PcepNaiIpv6NodeId) {
|
||||||
|
PcepNaiIpv6NodeId other = (PcepNaiIpv6NodeId) obj;
|
||||||
|
return Objects.equals(this.ipv6NodeId, other.ipv6NodeId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("IPV6 node ID", ipv6NodeId)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
|
||||||
|
/**
|
||||||
|
* draft-ietf-pce-segment-routing-03 section 5.3.2.
|
||||||
|
*/
|
||||||
|
public static final byte ST_TYPE = 0x05;
|
||||||
|
|
||||||
|
private final int localNodeId;
|
||||||
|
private final int localInterfaceId;
|
||||||
|
private final int remoteNodeId;
|
||||||
|
private final int remoteInterfaceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize all the member variables.
|
||||||
|
*
|
||||||
|
* @param localNodeId local node id
|
||||||
|
* @param localInterfaceId local interface id
|
||||||
|
* @param remoteNodeId remote node id
|
||||||
|
* @param remoteInterfaceId remote interface id
|
||||||
|
*/
|
||||||
|
public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
|
||||||
|
int remoteInterfaceId) {
|
||||||
|
this.localNodeId = localNodeId;
|
||||||
|
this.localInterfaceId = localInterfaceId;
|
||||||
|
this.remoteNodeId = remoteNodeId;
|
||||||
|
this.remoteInterfaceId = remoteInterfaceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
|
||||||
|
*
|
||||||
|
* @param localNodeId local node id
|
||||||
|
* @param localInterfaceId local interface if
|
||||||
|
* @param remoteNodeId remote node id
|
||||||
|
* @param remoteInterfaceId remote interface id
|
||||||
|
* @return PCEP Nai Unnumbered Adjacency Ipv4 object
|
||||||
|
*/
|
||||||
|
public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
|
||||||
|
int remoteInterfaceId) {
|
||||||
|
return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getType() {
|
||||||
|
return ST_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer bb) {
|
||||||
|
int iLenStartIndex = bb.writerIndex();
|
||||||
|
bb.writeInt(localNodeId);
|
||||||
|
bb.writeInt(localInterfaceId);
|
||||||
|
bb.writeInt(remoteNodeId);
|
||||||
|
bb.writeInt(remoteInterfaceId);
|
||||||
|
return bb.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
|
||||||
|
*
|
||||||
|
* @param bb of type channel buffer
|
||||||
|
* @return object of PcepNAIUnnumberedAdjacencyIpv4
|
||||||
|
*/
|
||||||
|
public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
|
||||||
|
int localNodeId;
|
||||||
|
int localInterfaceId;
|
||||||
|
int remoteNodeId;
|
||||||
|
int remoteInterfaceId;
|
||||||
|
localNodeId = bb.readInt();
|
||||||
|
localInterfaceId = bb.readInt();
|
||||||
|
remoteNodeId = bb.readInt();
|
||||||
|
remoteInterfaceId = bb.readInt();
|
||||||
|
return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
|
||||||
|
PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
|
||||||
|
return Objects.equals(this.localNodeId, other.localNodeId)
|
||||||
|
&& Objects.equals(this.localInterfaceId, other.localInterfaceId)
|
||||||
|
&& Objects.equals(this.remoteNodeId, other.remoteNodeId)
|
||||||
|
&& Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("local Node Id", localNodeId)
|
||||||
|
.add("local Interface Id", localInterfaceId)
|
||||||
|
.add("remote Node Id", remoteNodeId)
|
||||||
|
.add("remote Interface Id:", remoteInterfaceId)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides PCEP Object Header which is common for all the objects.
|
* Provides PCEP Object Header which is common for all the objects.
|
||||||
* Reference : RFC 5440.
|
* Reference : RFC 5440.
|
||||||
@ -66,7 +68,6 @@ public class PcepObjectHeader {
|
|||||||
* @param bIFlag I flag
|
* @param bIFlag I flag
|
||||||
* @param objLen PCEP object length
|
* @param objLen PCEP object length
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public PcepObjectHeader(byte objClass, byte objType, boolean bPFlag, boolean bIFlag, short objLen) {
|
public PcepObjectHeader(byte objClass, byte objType, boolean bPFlag, boolean bIFlag, short objLen) {
|
||||||
this.objClass = objClass;
|
this.objClass = objClass;
|
||||||
this.objType = objType;
|
this.objType = objType;
|
||||||
@ -221,4 +222,15 @@ public class PcepObjectHeader {
|
|||||||
log.debug("P flag: " + bPFlag);
|
log.debug("P flag: " + bPFlag);
|
||||||
log.debug("I flag: " + bIFlag);
|
log.debug("I flag: " + bIFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Object class:", objClass)
|
||||||
|
.add("Object type:", objType)
|
||||||
|
.add("Object length:", objLen)
|
||||||
|
.add("P flag:", bPFlag)
|
||||||
|
.add("I flag:", bIFlag)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
|
||||||
|
public interface PcepRsvpErrorSpec extends PcepValueType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To write the object information to channelBuffer.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int write(ChannelBuffer cb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns class number.
|
||||||
|
*
|
||||||
|
* @return class number
|
||||||
|
*/
|
||||||
|
byte getClassNum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns class type.
|
||||||
|
*
|
||||||
|
* @return class type
|
||||||
|
*/
|
||||||
|
byte getClassType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String toString();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepRsvpIpv4ErrorSpec implements PcepRsvpErrorSpec {
|
||||||
|
|
||||||
|
/*
|
||||||
|
RSVP error spec object header.
|
||||||
|
0 1 2 3
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Length (bytes) | Class-Num | C-Type |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
// (Object contents) //
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
Ref : ERROR_SPEC @ RFC2205
|
||||||
|
|
||||||
|
IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| IPv4 Error Node Address (4 bytes) |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Flags | Error Code | Error Value |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
PcepRsvpSpecObjHeader objHeader;
|
||||||
|
public static final byte CLASS_NUM = 0x06;
|
||||||
|
public static final byte CLASS_TYPE = 0x01;
|
||||||
|
public static final byte CLASS_LENGTH = 0x0c;
|
||||||
|
private int ipv4Addr;
|
||||||
|
private byte flags;
|
||||||
|
private byte errCode;
|
||||||
|
private short errValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize obj header, ipv4 addr, flags, err code and err value.
|
||||||
|
*
|
||||||
|
* @param objHeader rsvp ipv4 error spec object header
|
||||||
|
* @param ipv4Addr ipv4 address
|
||||||
|
* @param flags flags value
|
||||||
|
* @param errCode error code value
|
||||||
|
* @param errValue error value
|
||||||
|
*/
|
||||||
|
public PcepRsvpIpv4ErrorSpec(PcepRsvpSpecObjHeader objHeader, int ipv4Addr, byte flags, byte errCode,
|
||||||
|
short errValue) {
|
||||||
|
this.objHeader = objHeader;
|
||||||
|
this.ipv4Addr = ipv4Addr;
|
||||||
|
this.flags = flags;
|
||||||
|
this.errCode = errCode;
|
||||||
|
this.errValue = errValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize ipv4 address, flags, err code and err value.
|
||||||
|
*
|
||||||
|
* @param ipv4Addr ipv4 address
|
||||||
|
* @param flags flags value
|
||||||
|
* @param errCode error code
|
||||||
|
* @param errValue error value
|
||||||
|
*/
|
||||||
|
public PcepRsvpIpv4ErrorSpec(int ipv4Addr, byte flags, byte errCode, short errValue) {
|
||||||
|
this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
|
||||||
|
this.ipv4Addr = ipv4Addr;
|
||||||
|
this.flags = flags;
|
||||||
|
this.errCode = errCode;
|
||||||
|
this.errValue = errValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) {
|
||||||
|
int objLenIndex = objHeader.write(cb);
|
||||||
|
cb.writeInt(ipv4Addr);
|
||||||
|
cb.writeByte(flags);
|
||||||
|
cb.writeByte(errCode);
|
||||||
|
cb.writeShort(errValue);
|
||||||
|
short objLen = (short) (cb.writerIndex() - objLenIndex);
|
||||||
|
cb.setShort(objLenIndex, objLen);
|
||||||
|
return objLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return PCEP rsvp IPv4 error spec object
|
||||||
|
*/
|
||||||
|
public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
|
||||||
|
PcepRsvpSpecObjHeader objHeader;
|
||||||
|
int ipv4Addr;
|
||||||
|
byte flags;
|
||||||
|
byte errCode;
|
||||||
|
short errValue;
|
||||||
|
|
||||||
|
objHeader = PcepRsvpSpecObjHeader.read(cb);
|
||||||
|
ipv4Addr = cb.readInt();
|
||||||
|
flags = cb.readByte();
|
||||||
|
errCode = cb.readByte();
|
||||||
|
errValue = cb.readShort();
|
||||||
|
return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return StatefulRsvpErrorSpecTlv.TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return CLASS_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassNum() {
|
||||||
|
return CLASS_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassType() {
|
||||||
|
return CLASS_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("IPv4 Address:", ipv4Addr)
|
||||||
|
.add("flags:", flags)
|
||||||
|
.add("error Code:", errCode)
|
||||||
|
.add("error Value:", errValue)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,152 @@
|
|||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec {
|
||||||
|
|
||||||
|
/*
|
||||||
|
0 1 2 3
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Length (bytes) | Class-Num | C-Type |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
// (Object contents) //
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
Ref : ERROR_SPEC @ RFC2205
|
||||||
|
|
||||||
|
IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
+ +
|
||||||
|
| |
|
||||||
|
+ IPv6 Error Node Address (16 bytes) +
|
||||||
|
| |
|
||||||
|
+ +
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Flags | Error Code | Error Value |
|
||||||
|
+-------------+-------------+-------------+-------------+ */
|
||||||
|
|
||||||
|
PcepRsvpSpecObjHeader objHeader;
|
||||||
|
public static final byte CLASS_NUM = 0x06;
|
||||||
|
public static final byte CLASS_TYPE = 0x02;
|
||||||
|
public static final byte CLASS_LENGTH = 0x18;
|
||||||
|
public static final byte IPV6_LEN = 0x10;
|
||||||
|
|
||||||
|
private byte[] ipv6Addr;
|
||||||
|
private byte flags;
|
||||||
|
private byte errCode;
|
||||||
|
private short errValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize obj header, ipv6 addr, flags, err code and err value.
|
||||||
|
*
|
||||||
|
* @param objHeader rsvp ipv6 error spec object header
|
||||||
|
* @param ipv6Addr ipv6 address
|
||||||
|
* @param flags flags value
|
||||||
|
* @param errCode error code
|
||||||
|
* @param errValue error value
|
||||||
|
*/
|
||||||
|
public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode,
|
||||||
|
short errValue) {
|
||||||
|
this.objHeader = objHeader;
|
||||||
|
this.ipv6Addr = ipv6Addr;
|
||||||
|
this.flags = flags;
|
||||||
|
this.errCode = errCode;
|
||||||
|
this.errValue = errValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize ipv6 addr, flags, err code and err value.
|
||||||
|
*
|
||||||
|
* @param ipv6Addr ipv6 address
|
||||||
|
* @param flags flags value
|
||||||
|
* @param errCode error code
|
||||||
|
* @param errValue error value
|
||||||
|
*/
|
||||||
|
public PcepRsvpIpv6ErrorSpec(byte[] ipv6Addr, byte flags, byte errCode, short errValue) {
|
||||||
|
this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
|
||||||
|
this.ipv6Addr = ipv6Addr;
|
||||||
|
this.flags = flags;
|
||||||
|
this.errCode = errCode;
|
||||||
|
this.errValue = errValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) {
|
||||||
|
int objLenIndex = objHeader.write(cb);
|
||||||
|
cb.writeBytes(ipv6Addr);
|
||||||
|
cb.writeByte(flags);
|
||||||
|
cb.writeByte(errCode);
|
||||||
|
cb.writeShort(errValue);
|
||||||
|
short objLen = (short) (cb.writerIndex() - objLenIndex);
|
||||||
|
cb.setShort(objLenIndex, objLen);
|
||||||
|
return objLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns PCEP rsvp IPv6 error spce object.
|
||||||
|
*
|
||||||
|
* @param cb channel buffer
|
||||||
|
* @return PCEP rsvp IPv6 error spce object
|
||||||
|
*/
|
||||||
|
public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
|
||||||
|
PcepRsvpSpecObjHeader objHeader;
|
||||||
|
byte[] ipv6Addr = new byte[IPV6_LEN];
|
||||||
|
byte flags;
|
||||||
|
byte errCode;
|
||||||
|
short errValue;
|
||||||
|
|
||||||
|
objHeader = PcepRsvpSpecObjHeader.read(cb);
|
||||||
|
cb.readBytes(ipv6Addr, 0, IPV6_LEN);
|
||||||
|
flags = cb.readByte();
|
||||||
|
errCode = cb.readByte();
|
||||||
|
errValue = cb.readShort();
|
||||||
|
return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return StatefulRsvpErrorSpecTlv.TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return CLASS_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassNum() {
|
||||||
|
return CLASS_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassType() {
|
||||||
|
return CLASS_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("IPv6 Address:", ipv6Addr)
|
||||||
|
.add("flags:", flags)
|
||||||
|
.add("error Code:", errCode)
|
||||||
|
.add("error Value:", errValue)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides PcepRsvpObjectHeader.
|
* Provides PcepRsvpObjectHeader.
|
||||||
*/
|
*/
|
||||||
@ -158,4 +160,13 @@ public class PcepRsvpObjectHeader {
|
|||||||
log.debug("Object C-Type: " + objClassType);
|
log.debug("Object C-Type: " + objClassType);
|
||||||
log.debug("Object Length: " + objLen);
|
log.debug("Object Length: " + objLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Object Class-Num: " , objClassNum)
|
||||||
|
.add("Object C-Type: " , objClassType)
|
||||||
|
.add("Object Length: " , objLen)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides PcepRsvpObjectHeader.
|
||||||
|
*/
|
||||||
|
public class PcepRsvpSpecObjHeader {
|
||||||
|
|
||||||
|
/*
|
||||||
|
0 1 2 3
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Length (bytes) | Class-Num | C-Type |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
// (Object contents) //
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
ERROR_SPEC object Header
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class);
|
||||||
|
|
||||||
|
private short objLen;
|
||||||
|
private byte objClassNum;
|
||||||
|
private byte objClassType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize length, class num and type.
|
||||||
|
*
|
||||||
|
* @param objLen object length
|
||||||
|
* @param objClassNum pcep rsvp error spec object class num
|
||||||
|
* @param objClassType pcep rsvp error spec object class type
|
||||||
|
*/
|
||||||
|
public PcepRsvpSpecObjHeader(short objLen, byte objClassNum, byte objClassType) {
|
||||||
|
this.objLen = objLen;
|
||||||
|
this.objClassNum = objClassNum;
|
||||||
|
this.objClassType = objClassType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Class num.
|
||||||
|
*
|
||||||
|
* @param value pcep rsvp error spec object class num
|
||||||
|
*/
|
||||||
|
public void setObjClassNum(byte value) {
|
||||||
|
this.objClassNum = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Class type.
|
||||||
|
*
|
||||||
|
* @param value pcep rsvp error spec object class type
|
||||||
|
*/
|
||||||
|
public void setObjClassType(byte value) {
|
||||||
|
this.objClassType = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Class Length.
|
||||||
|
*
|
||||||
|
* @param value pcep rsvp error spec object length
|
||||||
|
*/
|
||||||
|
public void setObjLen(short value) {
|
||||||
|
this.objLen = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Object Length.
|
||||||
|
*
|
||||||
|
* @return objLen pcep rsvp error spec object length
|
||||||
|
*/
|
||||||
|
public short getObjLen() {
|
||||||
|
return this.objLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Object num.
|
||||||
|
*
|
||||||
|
* @return objClassNum pcep rsvp error spec object class num
|
||||||
|
*/
|
||||||
|
public byte getObjClassNum() {
|
||||||
|
return this.objClassNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Object type.
|
||||||
|
*
|
||||||
|
* @return objClassType pcep rsvp error spec object class type
|
||||||
|
*/
|
||||||
|
public byte getObjClassType() {
|
||||||
|
return this.objClassType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
|
||||||
|
*
|
||||||
|
* @param bb of type channel buffer
|
||||||
|
* @return object length index
|
||||||
|
*/
|
||||||
|
public int write(ChannelBuffer bb) {
|
||||||
|
int objLenIndex = bb.writerIndex();
|
||||||
|
bb.writeShort(objLen);
|
||||||
|
bb.writeByte(objClassNum);
|
||||||
|
bb.writeByte(objClassType);
|
||||||
|
return bb.writerIndex() - objLenIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the PcepRsvpObjectHeader.
|
||||||
|
*
|
||||||
|
* @param bb of type channel buffer
|
||||||
|
* @return PcepRsvpObjectHeader
|
||||||
|
*/
|
||||||
|
public static PcepRsvpSpecObjHeader read(ChannelBuffer bb) {
|
||||||
|
byte objClassNum;
|
||||||
|
byte objClassType;
|
||||||
|
short objLen;
|
||||||
|
objLen = bb.readShort();
|
||||||
|
objClassNum = bb.readByte();
|
||||||
|
objClassType = bb.readByte();
|
||||||
|
|
||||||
|
return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the attribute of PcepRsvpObjectHeader.
|
||||||
|
*/
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("PcepObjectHeader");
|
||||||
|
log.debug("Object Class-Num: " + objClassNum);
|
||||||
|
log.debug("Object C-Type: " + objClassType);
|
||||||
|
log.debug("Object Length: " + objLen);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Object Class-Num: " , objClassNum)
|
||||||
|
.add("Object C-Type: " , objClassType)
|
||||||
|
.add("Object Length: " , objLen)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,222 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
public class PcepRsvpUserErrorSpec implements PcepRsvpErrorSpec {
|
||||||
|
|
||||||
|
/*
|
||||||
|
RSVP error spec object header.
|
||||||
|
0 1 2 3
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Length (bytes) | Class-Num | C-Type |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
// (Object contents) //
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
Ref : USER_ERROR_SPEC @ RFC5284.
|
||||||
|
USER_ERROR_SPEC object: Class = 194, C-Type = 1
|
||||||
|
|
||||||
|
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
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| Enterprise Number |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| Sub Org | Err Desc Len | User Error Value |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| |
|
||||||
|
~ Error Description ~
|
||||||
|
| |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| |
|
||||||
|
~ User-Defined Subobjects ~
|
||||||
|
| |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final byte CLASS_NUM = (byte) 0xc2;
|
||||||
|
public static final byte CLASS_TYPE = 0x01;
|
||||||
|
|
||||||
|
private PcepRsvpSpecObjHeader objHeader;
|
||||||
|
private int enterpriseNum;
|
||||||
|
private byte subOrg;
|
||||||
|
private byte errDescLen;
|
||||||
|
private short userErrorValue;
|
||||||
|
private byte[] errDesc;
|
||||||
|
private LinkedList<PcepValueType> llRsvpUserSpecSubObj;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param objHeader pcep rsvp spec object header
|
||||||
|
* @param enterpriseNum enterprise number
|
||||||
|
* @param subOrg organization identifier value
|
||||||
|
* @param errDescLen error description length
|
||||||
|
* @param userErrorValue user error value
|
||||||
|
* @param errDesc error description
|
||||||
|
* @param llRsvpUserSpecSubObj list of subobjects
|
||||||
|
*/
|
||||||
|
public PcepRsvpUserErrorSpec(PcepRsvpSpecObjHeader objHeader, int enterpriseNum, byte subOrg, byte errDescLen,
|
||||||
|
short userErrorValue, byte[] errDesc, LinkedList<PcepValueType> llRsvpUserSpecSubObj) {
|
||||||
|
this.objHeader = objHeader;
|
||||||
|
this.enterpriseNum = enterpriseNum;
|
||||||
|
this.subOrg = subOrg;
|
||||||
|
this.errDescLen = errDescLen;
|
||||||
|
this.userErrorValue = userErrorValue;
|
||||||
|
this.errDesc = errDesc;
|
||||||
|
this.llRsvpUserSpecSubObj = llRsvpUserSpecSubObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer cb) {
|
||||||
|
int objLenIndex = objHeader.write(cb);
|
||||||
|
cb.writeInt(enterpriseNum);
|
||||||
|
cb.writeByte(subOrg);
|
||||||
|
cb.writeByte(errDescLen);
|
||||||
|
cb.writeShort(userErrorValue);
|
||||||
|
cb.writeBytes(errDesc);
|
||||||
|
|
||||||
|
if (null != llRsvpUserSpecSubObj) {
|
||||||
|
|
||||||
|
ListIterator<PcepValueType> listIterator = llRsvpUserSpecSubObj.listIterator();
|
||||||
|
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
PcepValueType tlv = listIterator.next();
|
||||||
|
if (null == tlv) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tlv.write(cb);
|
||||||
|
// need to take care of padding
|
||||||
|
int pad = tlv.getLength() % 4;
|
||||||
|
if (0 != pad) {
|
||||||
|
pad = 4 - pad;
|
||||||
|
for (int i = 0; i < pad; ++i) {
|
||||||
|
cb.writeByte((byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
short objLen = (short) (cb.writerIndex() - objLenIndex);
|
||||||
|
cb.setShort(objLenIndex, objLen);
|
||||||
|
return objLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of PcepRsvpErrorSpec.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return object of PcepRsvpErrorSpec
|
||||||
|
* @throws PcepParseException when expected object is not received
|
||||||
|
*/
|
||||||
|
public static PcepRsvpErrorSpec read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
PcepRsvpSpecObjHeader objHeader;
|
||||||
|
int enterpriseNum;
|
||||||
|
byte subOrg;
|
||||||
|
byte errDescLen;
|
||||||
|
short userErrorValue;
|
||||||
|
byte[] errDesc;
|
||||||
|
LinkedList<PcepValueType> llRsvpUserSpecSubObj = null;
|
||||||
|
|
||||||
|
objHeader = PcepRsvpSpecObjHeader.read(cb);
|
||||||
|
|
||||||
|
if (CLASS_NUM != objHeader.getObjClassNum() || CLASS_TYPE != objHeader.getObjClassType()) {
|
||||||
|
throw new PcepParseException("Expected PcepRsvpUserErrorSpec object.");
|
||||||
|
}
|
||||||
|
enterpriseNum = cb.readInt();
|
||||||
|
subOrg = cb.readByte();
|
||||||
|
errDescLen = cb.readByte();
|
||||||
|
userErrorValue = cb.readShort();
|
||||||
|
errDesc = new byte[errDescLen];
|
||||||
|
cb.readBytes(errDesc, 0, errDescLen);
|
||||||
|
|
||||||
|
llRsvpUserSpecSubObj = parseErrSpecSubObj(cb);
|
||||||
|
|
||||||
|
return new PcepRsvpUserErrorSpec(objHeader, enterpriseNum, subOrg, errDescLen, userErrorValue, errDesc,
|
||||||
|
llRsvpUserSpecSubObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LinkedList<PcepValueType> parseErrSpecSubObj(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
LinkedList<PcepValueType> llRsvpUserSpecSubObj = new LinkedList<PcepValueType>();
|
||||||
|
while (0 < cb.readableBytes()) {
|
||||||
|
PcepValueType tlv = null;
|
||||||
|
short hType = cb.readShort();
|
||||||
|
int iValue = 0;
|
||||||
|
//short hLength = cb.readShort();
|
||||||
|
switch (hType) {
|
||||||
|
case AutonomousSystemTlv.TYPE:
|
||||||
|
iValue = cb.readInt();
|
||||||
|
tlv = new AutonomousSystemTlv(iValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
|
||||||
|
}
|
||||||
|
llRsvpUserSpecSubObj.add(tlv);
|
||||||
|
}
|
||||||
|
return llRsvpUserSpecSubObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return StatefulRsvpErrorSpecTlv.TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return objHeader.getObjLen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassNum() {
|
||||||
|
return CLASS_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getClassType() {
|
||||||
|
return CLASS_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("enterprise Number:", enterpriseNum)
|
||||||
|
.add("sub Organization:", subOrg)
|
||||||
|
.add("err Desc Length:", errDescLen)
|
||||||
|
.add("user Error Value:", userErrorValue)
|
||||||
|
.add("err Desc:", errDesc)
|
||||||
|
.add("Rsvp User Spec Sub Object:", llRsvpUserSpecSubObj)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,336 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepNai;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provides SrEroSubObject.
|
||||||
|
*/
|
||||||
|
public class SrEroSubObject implements PcepValueType {
|
||||||
|
/*
|
||||||
|
SR-ERO subobject: (draft-ietf-pce-segment-routing-00)
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|L| Type | Length | ST | Flags |F|S|C|M|
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| SID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// NAI (variable) //
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAI
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Local IPv4 address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Remote IPv4 address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
NAI for IPv4 Adjacency
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// Local IPv6 address (16 bytes) //
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// Remote IPv6 address (16 bytes) //
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
NAI for IPv6 adjacency
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Local Node-ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Local Interface ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Remote Node-ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Remote Interface ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
NAI for Unnumbered adjacency with IPv4 Node IDs
|
||||||
|
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(SrEroSubObject.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 0x60; //TODO : type to be defined
|
||||||
|
public static final short LENGTH = 12;
|
||||||
|
public static final short VALUE_LENGTH = 10;
|
||||||
|
public static final int SET = 1;
|
||||||
|
public static final byte MFLAG_SET = 0x01;
|
||||||
|
public static final byte CFLAG_SET = 0x02;
|
||||||
|
public static final byte SFLAG_SET = 0x04;
|
||||||
|
public static final byte FFLAG_SET = 0x08;
|
||||||
|
public static final byte SHIFT_ST = 12;
|
||||||
|
|
||||||
|
private final boolean bFFlag;
|
||||||
|
private final boolean bSFlag;
|
||||||
|
private final boolean bCFlag;
|
||||||
|
private final boolean bMFlag;
|
||||||
|
private final byte st;
|
||||||
|
|
||||||
|
private final int sID;
|
||||||
|
private final PcepNai nai;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param st SID type
|
||||||
|
* @param bFFlag F flag
|
||||||
|
* @param bSFlag S flag
|
||||||
|
* @param bCFlag C flag
|
||||||
|
* @param bMFlag M flag
|
||||||
|
* @param sID segment identifier value
|
||||||
|
* @param nai NAI associated with SID
|
||||||
|
*/
|
||||||
|
public SrEroSubObject(byte st, boolean bFFlag, boolean bSFlag, boolean bCFlag, boolean bMFlag, int sID,
|
||||||
|
PcepNai nai) {
|
||||||
|
this.st = st;
|
||||||
|
this.bFFlag = bFFlag;
|
||||||
|
this.bSFlag = bSFlag;
|
||||||
|
this.bCFlag = bCFlag;
|
||||||
|
this.bMFlag = bMFlag;
|
||||||
|
this.sID = sID;
|
||||||
|
this.nai = nai;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates object of SrEroSubObject.
|
||||||
|
*
|
||||||
|
* @param st SID type
|
||||||
|
* @param bFFlag F flag
|
||||||
|
* @param bSFlag S flag
|
||||||
|
* @param bCFlag C flag
|
||||||
|
* @param bMFlag M flag
|
||||||
|
* @param sID segment identifier value
|
||||||
|
* @param nai NAI associated with SID
|
||||||
|
* @return object of SrEroSubObject
|
||||||
|
*/
|
||||||
|
public static SrEroSubObject of(byte st, boolean bFFlag, boolean bSFlag, boolean bCFlag, boolean bMFlag, int sID,
|
||||||
|
PcepNai nai) {
|
||||||
|
return new SrEroSubObject(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SID type.
|
||||||
|
* @return st sid type
|
||||||
|
*/
|
||||||
|
public byte getSt() {
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns bFFlag.
|
||||||
|
* @return bFFlag
|
||||||
|
*/
|
||||||
|
public boolean getFFlag() {
|
||||||
|
return bFFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns bSFlag.
|
||||||
|
* @return bSFlag
|
||||||
|
*/
|
||||||
|
public boolean getSFlag() {
|
||||||
|
return bSFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns bCFlag.
|
||||||
|
* @return bCFlag
|
||||||
|
*/
|
||||||
|
public boolean getCFlag() {
|
||||||
|
return bCFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns bMFlag.
|
||||||
|
* @return bMFlag
|
||||||
|
*/
|
||||||
|
public boolean getMFlag() {
|
||||||
|
return bMFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns sID.
|
||||||
|
* @return sID
|
||||||
|
*/
|
||||||
|
public int getSID() {
|
||||||
|
return sID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns nai.
|
||||||
|
* @return nai
|
||||||
|
*/
|
||||||
|
public PcepNai getNai() {
|
||||||
|
return nai;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof SrEroSubObject) {
|
||||||
|
SrEroSubObject other = (SrEroSubObject) obj;
|
||||||
|
return Objects.equals(this.st, other.st) && Objects.equals(this.bFFlag, other.bFFlag)
|
||||||
|
&& Objects.equals(this.bSFlag, other.bSFlag) && Objects.equals(this.bCFlag, other.bCFlag)
|
||||||
|
&& Objects.equals(this.bMFlag, other.bMFlag) && Objects.equals(this.sID, other.sID)
|
||||||
|
&& Objects.equals(this.nai, other.nai);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
|
||||||
|
short temp = 0;
|
||||||
|
if (bMFlag) {
|
||||||
|
temp = (short) (temp | MFLAG_SET);
|
||||||
|
}
|
||||||
|
if (bCFlag) {
|
||||||
|
temp = (short) (temp | CFLAG_SET);
|
||||||
|
}
|
||||||
|
if (bSFlag) {
|
||||||
|
temp = (short) (temp | SFLAG_SET);
|
||||||
|
}
|
||||||
|
if (bFFlag) {
|
||||||
|
temp = (short) (temp | FFLAG_SET);
|
||||||
|
}
|
||||||
|
short tempST = (short) (st << SHIFT_ST);
|
||||||
|
temp = (short) (temp | tempST);
|
||||||
|
c.writeShort(temp);
|
||||||
|
c.writeInt(sID);
|
||||||
|
nai.write(c);
|
||||||
|
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of SrEroSubObject.
|
||||||
|
* @param c of type channel buffer
|
||||||
|
* @return object of SrEroSubObject
|
||||||
|
*/
|
||||||
|
public static PcepValueType read(ChannelBuffer c) {
|
||||||
|
short temp = c.readShort();
|
||||||
|
boolean bMFlag;
|
||||||
|
boolean bCFlag;
|
||||||
|
boolean bSFlag;
|
||||||
|
boolean bFFlag;
|
||||||
|
byte st;
|
||||||
|
PcepNai nai = null;
|
||||||
|
|
||||||
|
bMFlag = (temp & MFLAG_SET) == MFLAG_SET ? true : false;
|
||||||
|
bCFlag = (temp & CFLAG_SET) == CFLAG_SET ? true : false;
|
||||||
|
bSFlag = (temp & SFLAG_SET) == SFLAG_SET ? true : false;
|
||||||
|
bFFlag = (temp & FFLAG_SET) == FFLAG_SET ? true : false;
|
||||||
|
|
||||||
|
st = (byte) (temp >> SHIFT_ST);
|
||||||
|
|
||||||
|
int sID = c.readInt();
|
||||||
|
switch (st) {
|
||||||
|
case 0x01:
|
||||||
|
nai = PcepNaiIpv4NodeId.read(c);
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
nai = PcepNaiIpv6NodeId.read(c);
|
||||||
|
break;
|
||||||
|
case 0x03:
|
||||||
|
nai = PcepNaiIpv4Adjacency.read(c);
|
||||||
|
break;
|
||||||
|
case 0x04:
|
||||||
|
nai = PcepNaiIpv6Adjacency.read(c);
|
||||||
|
break;
|
||||||
|
case 0x05:
|
||||||
|
nai = PcepNaiUnnumberedAdjacencyIpv4.read(c);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nai = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SrEroSubObject(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("SrEroSubObject");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
|
||||||
|
log.debug("st:" + st + " bFFlag:" + bFFlag + " bSFlag:" + bSFlag + " bCFlag:" + bCFlag + " bMFlag:" + bMFlag
|
||||||
|
+ " sID:" + sID + " nAI:" + nai);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Type", TYPE)
|
||||||
|
.add("Length", LENGTH)
|
||||||
|
.add("st", st)
|
||||||
|
.add("bFflag", bFFlag)
|
||||||
|
.add("bSFlag", bSFlag)
|
||||||
|
.add("bCFlag", bCFlag)
|
||||||
|
.add("bMFlag", bMFlag)
|
||||||
|
.add("sID", sID)
|
||||||
|
.add("nAI", nai)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides StatefulIPv4LspIdentidiersTlv.
|
||||||
|
*/
|
||||||
|
public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
|
||||||
|
|
||||||
|
/* IPV4-LSP-IDENTIFIERS TLV format
|
||||||
|
*
|
||||||
|
* Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
|
||||||
|
*
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type=18 | Length=16 |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv4 Tunnel Sender Address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| LSP ID | Tunnel ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Extended Tunnel ID |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| IPv4 Tunnel Endpoint Address |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 18;
|
||||||
|
public static final short LENGTH = 16;
|
||||||
|
public static final int VALUE_LENGTH = 16;
|
||||||
|
private final int ipv4IngressAddress;
|
||||||
|
private final short lspId;
|
||||||
|
private final short tunnelId;
|
||||||
|
private final int extendedTunnelId;
|
||||||
|
private final int ipv4EgressAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize member variables.
|
||||||
|
*
|
||||||
|
* @param ipv4IngressAddress ingress ipv4 address
|
||||||
|
* @param lspId lsp id
|
||||||
|
* @param tunnelId tunnel id
|
||||||
|
* @param extendedTunnelId extended tunnel id
|
||||||
|
* @param ipv4EgressAddress egress ipv4 address
|
||||||
|
*/
|
||||||
|
public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
|
||||||
|
int ipv4EgressAddress) {
|
||||||
|
|
||||||
|
this.ipv4IngressAddress = ipv4IngressAddress;
|
||||||
|
this.lspId = lspId;
|
||||||
|
this.tunnelId = tunnelId;
|
||||||
|
this.extendedTunnelId = extendedTunnelId;
|
||||||
|
this.ipv4EgressAddress = ipv4EgressAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates object of StatefulIPv4LspIdentidiersTlv.
|
||||||
|
*
|
||||||
|
* @param ipv4IngressAddress ingress ipv4 address
|
||||||
|
* @param lspId lsp id
|
||||||
|
* @param tunnelId tunnel id
|
||||||
|
* @param extendedTunnelId extended tunnel id
|
||||||
|
* @param ipv4EgressAddress egress ipv4 address
|
||||||
|
* @return object of StatefulIPv4LspIdentidiersTlv
|
||||||
|
*/
|
||||||
|
public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
|
||||||
|
int extendedTunnelId, int ipv4EgressAddress) {
|
||||||
|
return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
|
||||||
|
ipv4EgressAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns tunnel id.
|
||||||
|
*
|
||||||
|
* @return tunnelId
|
||||||
|
*/
|
||||||
|
public short getTunnelId() {
|
||||||
|
return this.tunnelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns extendedTunnelId.
|
||||||
|
*
|
||||||
|
* @return extendedTunnelId
|
||||||
|
*/
|
||||||
|
public int getextendedTunnelId() {
|
||||||
|
return this.extendedTunnelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ipv4IngressAddress.
|
||||||
|
*
|
||||||
|
* @return ipv4IngressAddress
|
||||||
|
*/
|
||||||
|
public int getIpv4IngressAddress() {
|
||||||
|
return ipv4IngressAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ipv4EgressAddress.
|
||||||
|
*
|
||||||
|
* @return ipv4EgressAddress
|
||||||
|
*/
|
||||||
|
public int getIpv4EgressAddress() {
|
||||||
|
return ipv4EgressAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof StatefulIPv4LspIdentidiersTlv) {
|
||||||
|
StatefulIPv4LspIdentidiersTlv other = (StatefulIPv4LspIdentidiersTlv) obj;
|
||||||
|
return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress)
|
||||||
|
&& Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId)
|
||||||
|
&& Objects.equals(this.extendedTunnelId, other.extendedTunnelId)
|
||||||
|
&& Objects.equals(this.ipv4EgressAddress, other.ipv4EgressAddress);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
c.writeInt(ipv4IngressAddress);
|
||||||
|
c.writeShort(lspId);
|
||||||
|
c.writeShort(tunnelId);
|
||||||
|
c.writeInt(extendedTunnelId);
|
||||||
|
c.writeInt(ipv4EgressAddress);
|
||||||
|
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv.
|
||||||
|
*
|
||||||
|
* @param c of type channel buffer
|
||||||
|
* @return object of StatefulIPv4LspIdentidiersTlv
|
||||||
|
*/
|
||||||
|
public static PcepValueType read(ChannelBuffer c) {
|
||||||
|
int ipv4IngressAddress = c.readInt();
|
||||||
|
short lspId = c.readShort();
|
||||||
|
short tunnelId = c.readShort();
|
||||||
|
int extendedTunnelId = c.readInt();
|
||||||
|
int ipv4EgressAddress = c.readInt();
|
||||||
|
return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
|
||||||
|
ipv4EgressAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("StatefulIPv4LspIdentidiersTlv");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
log.debug("Ipv4IngressAddress: " + ipv4IngressAddress);
|
||||||
|
log.debug("LspId: " + lspId);
|
||||||
|
log.debug("TunnelId: " + tunnelId);
|
||||||
|
log.debug("ExtendedTunnelId: " + extendedTunnelId);
|
||||||
|
log.debug("Ipv4EgressAddress: " + ipv4EgressAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass())
|
||||||
|
.add("Type:", TYPE)
|
||||||
|
.add("Length:", LENGTH)
|
||||||
|
.add("Ipv4IngressAddress:", ipv4IngressAddress)
|
||||||
|
.add("LspId:", lspId)
|
||||||
|
.add("TunnelId:", tunnelId)
|
||||||
|
.add("ExtendedTunnelId:", extendedTunnelId)
|
||||||
|
.add("Ipv4EgressAddress:", ipv4EgressAddress)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides StatefulLspErrorCodeTlv.
|
||||||
|
*/
|
||||||
|
public class StatefulLspErrorCodeTlv implements PcepValueType {
|
||||||
|
|
||||||
|
/* LSP-ERROR-CODE TLV format
|
||||||
|
*
|
||||||
|
* Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
|
||||||
|
*
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type=20 | Length=4 |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| LSP Error Code |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(StatefulLspErrorCodeTlv.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 20;
|
||||||
|
public static final short LENGTH = 4;
|
||||||
|
private final int rawValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize raw Value.
|
||||||
|
*
|
||||||
|
* @param rawValue lsp error code value
|
||||||
|
*/
|
||||||
|
public StatefulLspErrorCodeTlv(int rawValue) {
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates object of StatefulLspErrorCodeTlv.
|
||||||
|
*
|
||||||
|
* @param raw lsp error code value
|
||||||
|
* @return object of StatefulLspErrorCodeTlv
|
||||||
|
*/
|
||||||
|
public static StatefulLspErrorCodeTlv of(int raw) {
|
||||||
|
return new StatefulLspErrorCodeTlv(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns lsp error code value.
|
||||||
|
*
|
||||||
|
* @return lsp error code value
|
||||||
|
*/
|
||||||
|
public int getInt() {
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof StatefulLspErrorCodeTlv) {
|
||||||
|
StatefulLspErrorCodeTlv other = (StatefulLspErrorCodeTlv) obj;
|
||||||
|
return Objects.equals(this.rawValue, other.rawValue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(LENGTH);
|
||||||
|
c.writeInt(rawValue);
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the channel buffer and returns object of StatefulLspErrorCodeTlv.
|
||||||
|
*
|
||||||
|
* @param c of type channel buffer
|
||||||
|
* @return object of StatefulLspErrorCodeTlv
|
||||||
|
*/
|
||||||
|
public static StatefulLspErrorCodeTlv read(ChannelBuffer c) {
|
||||||
|
return StatefulLspErrorCodeTlv.of(c.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("StatefulLspErrorCodeTlv");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + LENGTH);
|
||||||
|
log.debug("Value: " + rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,235 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides StatefulRsvpErrorSpecTlv.
|
||||||
|
*/
|
||||||
|
public class StatefulRsvpErrorSpecTlv implements PcepValueType {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(StatefulRsvpErrorSpecTlv.class);
|
||||||
|
|
||||||
|
/* RSVP-ERROR-SPEC TLV format
|
||||||
|
* Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
|
||||||
|
*
|
||||||
|
*
|
||||||
|
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type=21 | Length (variable) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
+ RSVP ERROR_SPEC or USER_ERROR_SPEC Object +
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
0 1 2 3
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Length (bytes) | Class-Num | C-Type |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
// (Object contents) //
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
Ref : ERROR_SPEC @ RFC2205
|
||||||
|
|
||||||
|
IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| IPv4 Error Node Address (4 bytes) |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Flags | Error Code | Error Value |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
|
||||||
|
IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| |
|
||||||
|
+ +
|
||||||
|
| |
|
||||||
|
+ IPv6 Error Node Address (16 bytes) +
|
||||||
|
| |
|
||||||
|
+ +
|
||||||
|
| |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
| Flags | Error Code | Error Value |
|
||||||
|
+-------------+-------------+-------------+-------------+
|
||||||
|
|
||||||
|
|
||||||
|
Ref : USER_ERROR_SPEC @ RFC5284
|
||||||
|
USER_ERROR_SPEC object: Class = 194, C-Type = 1
|
||||||
|
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
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| Enterprise Number |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| Sub Org | Err Desc Len | User Error Value |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| |
|
||||||
|
~ Error Description ~
|
||||||
|
| |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
| |
|
||||||
|
~ User-Defined Subobjects ~
|
||||||
|
| |
|
||||||
|
+---------------+---------------+---------------+---------------+
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final short TYPE = 21;
|
||||||
|
public static final int OBJECT_HEADER_LENGTH = 4;
|
||||||
|
private final short hLength;
|
||||||
|
|
||||||
|
private final PcepRsvpErrorSpec rsvpErrSpecObj;
|
||||||
|
private final boolean isErrSpceObjSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize errSpecObj.
|
||||||
|
*
|
||||||
|
* @param rsvpErrSpecObj Rsvp error spec object
|
||||||
|
* @param hLength length of rsvp error spec object
|
||||||
|
*/
|
||||||
|
public StatefulRsvpErrorSpecTlv(PcepRsvpErrorSpec rsvpErrSpecObj, short hLength) {
|
||||||
|
this.rsvpErrSpecObj = rsvpErrSpecObj;
|
||||||
|
this.isErrSpceObjSet = true;
|
||||||
|
this.hLength = hLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns PcepRsvpErrorSpecObject.
|
||||||
|
*
|
||||||
|
* @return rsvpErrSpecObj
|
||||||
|
*/
|
||||||
|
public PcepRsvpErrorSpec getPcepRsvpErrorSpec() {
|
||||||
|
return this.rsvpErrSpecObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return hLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads channel buffer and returns object of StatefulRsvpErrorSpecTlv.
|
||||||
|
*
|
||||||
|
* @param cb of type channel buffer
|
||||||
|
* @return object of StatefulRsvpErrorSpecTlv
|
||||||
|
*/
|
||||||
|
public static PcepValueType read(ChannelBuffer cb) throws PcepParseException {
|
||||||
|
|
||||||
|
PcepRsvpErrorSpec rsvpErrSpecObj = null;
|
||||||
|
PcepRsvpSpecObjHeader rsvpErrSpecObjHeader;
|
||||||
|
|
||||||
|
cb.markReaderIndex();
|
||||||
|
rsvpErrSpecObjHeader = PcepRsvpSpecObjHeader.read(cb);
|
||||||
|
cb.resetReaderIndex();
|
||||||
|
|
||||||
|
if (PcepRsvpIpv4ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
|
||||||
|
&& PcepRsvpIpv4ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
|
||||||
|
rsvpErrSpecObj = PcepRsvpIpv4ErrorSpec.read(cb);
|
||||||
|
} else if (PcepRsvpIpv6ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
|
||||||
|
&& PcepRsvpIpv6ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
|
||||||
|
rsvpErrSpecObj = PcepRsvpIpv6ErrorSpec.read(cb);
|
||||||
|
} else if (PcepRsvpUserErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
|
||||||
|
&& PcepRsvpUserErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
|
||||||
|
rsvpErrSpecObj = PcepRsvpUserErrorSpec.read(cb);
|
||||||
|
}
|
||||||
|
return rsvpErrSpecObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(rsvpErrSpecObj.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof StatefulRsvpErrorSpecTlv) {
|
||||||
|
StatefulRsvpErrorSpecTlv other = (StatefulRsvpErrorSpecTlv) obj;
|
||||||
|
return Objects.equals(this.rsvpErrSpecObj, other.rsvpErrSpecObj);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
int tlvLenIndex = c.writerIndex();
|
||||||
|
c.writeShort(hLength);
|
||||||
|
if (isErrSpceObjSet) {
|
||||||
|
rsvpErrSpecObj.write(c);
|
||||||
|
}
|
||||||
|
short tlvLen = (short) (c.writerIndex() - iStartIndex + 4);
|
||||||
|
c.setShort(tlvLenIndex, tlvLen);
|
||||||
|
|
||||||
|
return tlvLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
|
||||||
|
log.debug("StatefulRsvpErrorSpecTlv");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + hLength);
|
||||||
|
if (isErrSpceObjSet) {
|
||||||
|
rsvpErrSpecObj.print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
|
||||||
|
|
||||||
|
if (!isErrSpceObjSet) {
|
||||||
|
toStrHelper
|
||||||
|
.add("Type", TYPE)
|
||||||
|
.add("Length", hLength);
|
||||||
|
} else {
|
||||||
|
toStrHelper
|
||||||
|
.add("Type", TYPE)
|
||||||
|
.add("Length", hLength)
|
||||||
|
.add("RSVP Error Spec Object", rsvpErrSpecObj);
|
||||||
|
}
|
||||||
|
return toStrHelper.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.pcepio.types;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepVersion;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides SymbolicPathNameTlv.
|
||||||
|
*/
|
||||||
|
public class SymbolicPathNameTlv implements PcepValueType {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SYMBOLIC-PATH-NAME TLV format
|
||||||
|
* Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
|
||||||
|
*
|
||||||
|
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
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Type=17 | Length (variable) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
// Symbolic Path Name //
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(SymbolicPathNameTlv.class);
|
||||||
|
|
||||||
|
public static final short TYPE = 17;
|
||||||
|
private short hLength;
|
||||||
|
|
||||||
|
private final byte[] rawValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize raw Value.
|
||||||
|
*
|
||||||
|
* @param rawValue Symbolic path name
|
||||||
|
*/
|
||||||
|
public SymbolicPathNameTlv(byte[] rawValue) {
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
this.hLength = (short) rawValue.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize raw Value.
|
||||||
|
*
|
||||||
|
* @param rawValue Symbolic path name
|
||||||
|
* @param hLength length of Symbolic path name
|
||||||
|
*/
|
||||||
|
public SymbolicPathNameTlv(byte[] rawValue, short hLength) {
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
if (0 == hLength) {
|
||||||
|
this.hLength = (short) rawValue.length;
|
||||||
|
} else {
|
||||||
|
this.hLength = hLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an object of SymbolicPathNameTlv.
|
||||||
|
*
|
||||||
|
* @param raw Symbolic path name
|
||||||
|
* @param hLength length of Symbolic path name
|
||||||
|
* @return object of SymbolicPathNameTlv
|
||||||
|
*/
|
||||||
|
public static SymbolicPathNameTlv of(final byte[] raw, short hLength) {
|
||||||
|
return new SymbolicPathNameTlv(raw, hLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Symbolic path name.
|
||||||
|
*
|
||||||
|
* @return Symbolic path name byte array
|
||||||
|
*/
|
||||||
|
public byte[] getValue() {
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PcepVersion getVersion() {
|
||||||
|
return PcepVersion.PCEP_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getLength() {
|
||||||
|
return hLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof SymbolicPathNameTlv) {
|
||||||
|
SymbolicPathNameTlv other = (SymbolicPathNameTlv) obj;
|
||||||
|
return Objects.equals(this.rawValue, other.rawValue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int write(ChannelBuffer c) {
|
||||||
|
int iLenStartIndex = c.writerIndex();
|
||||||
|
c.writeShort(TYPE);
|
||||||
|
c.writeShort(hLength);
|
||||||
|
c.writeBytes(rawValue);
|
||||||
|
return c.writerIndex() - iLenStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads channel buffer and returns object of SymbolicPathNameTlv.
|
||||||
|
*
|
||||||
|
* @param c of type channel buffer
|
||||||
|
* @param hLength length of bytes to read
|
||||||
|
* @return object of SymbolicPathNameTlv
|
||||||
|
*/
|
||||||
|
public static SymbolicPathNameTlv read(ChannelBuffer c, short hLength) {
|
||||||
|
byte[] symbolicPathName = new byte[hLength];
|
||||||
|
c.readBytes(symbolicPathName, 0, hLength);
|
||||||
|
return new SymbolicPathNameTlv(symbolicPathName, hLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.debug("SymbolicPathNameTlv");
|
||||||
|
log.debug("Type: " + TYPE);
|
||||||
|
log.debug("Length: " + hLength);
|
||||||
|
log.debug("Symbolic Path Name : " + rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return MoreObjects.toStringHelper(getClass()).add("Symbolic Path Name ", rawValue).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014-2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepFactories;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessage;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepCloseMsg;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class PcepCloseMsgTest {
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepCloseMsgTest.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void startUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void closeMessageTest1() throws PcepParseException {
|
||||||
|
byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, /* common header */
|
||||||
|
0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
|
||||||
|
|
||||||
|
byte[] testCloseMsg = {0};
|
||||||
|
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
|
||||||
|
buffer.writeBytes(closeMsg);
|
||||||
|
|
||||||
|
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
|
||||||
|
PcepMessage message = null;
|
||||||
|
try {
|
||||||
|
message = reader.readFrom(buffer);
|
||||||
|
} catch (PcepParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message instanceof PcepCloseMsg) {
|
||||||
|
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
|
||||||
|
message.writeTo(buf);
|
||||||
|
testCloseMsg = buf.array();
|
||||||
|
|
||||||
|
int iReadLen = buf.writerIndex() - 0;
|
||||||
|
testCloseMsg = new byte[iReadLen];
|
||||||
|
buf.readBytes(testCloseMsg, 0, iReadLen);
|
||||||
|
if (Arrays.equals(closeMsg, testCloseMsg)) {
|
||||||
|
Assert.assertArrayEquals(closeMsg, testCloseMsg);
|
||||||
|
log.debug("CloseMsg are equal :" + closeMsg);
|
||||||
|
} else {
|
||||||
|
Assert.fail("test case failed");
|
||||||
|
log.debug("not equal");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Assert.fail("test case failed");
|
||||||
|
log.debug("not equal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014-2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.onosproject.pcepio.exceptions.PcepParseException;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepFactories;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessage;
|
||||||
|
import org.onosproject.pcepio.protocol.PcepMessageReader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class PcepKeepaliveMsgTest {
|
||||||
|
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(PcepKeepaliveMsgTest.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void startUp() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void keepaliveMessageTest1() throws PcepParseException {
|
||||||
|
|
||||||
|
byte[] keepaliveMsg = new byte[] {0x20, 0x02, 0x00, 0x04 };
|
||||||
|
|
||||||
|
byte[] testKeepaliveMsg = {0};
|
||||||
|
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
|
||||||
|
buffer.writeBytes(keepaliveMsg);
|
||||||
|
|
||||||
|
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
|
||||||
|
PcepMessage message = null;
|
||||||
|
try {
|
||||||
|
message = reader.readFrom(buffer);
|
||||||
|
} catch (PcepParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message instanceof PcepKeepaliveMsg) {
|
||||||
|
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
|
||||||
|
message.writeTo(buf);
|
||||||
|
testKeepaliveMsg = buf.array();
|
||||||
|
|
||||||
|
int iReadLen = buf.writerIndex() - 0;
|
||||||
|
testKeepaliveMsg = new byte[iReadLen];
|
||||||
|
buf.readBytes(testKeepaliveMsg, 0, iReadLen);
|
||||||
|
|
||||||
|
if (Arrays.equals(keepaliveMsg, testKeepaliveMsg)) {
|
||||||
|
Assert.assertArrayEquals(keepaliveMsg, testKeepaliveMsg);
|
||||||
|
log.debug("keepaliveMsg are equal :" + keepaliveMsg);
|
||||||
|
} else {
|
||||||
|
Assert.fail("test case failed");
|
||||||
|
log.debug("not equal");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Assert.fail("test case failed");
|
||||||
|
log.debug("not equal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.pcepio;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
|
||||||
|
|
||||||
|
import com.google.common.testing.EqualsTester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for Symbolic path tlv.
|
||||||
|
*/
|
||||||
|
public class SymbolicPathNameTlvTest {
|
||||||
|
|
||||||
|
byte[] value1 = {0x41 };
|
||||||
|
Short length1 = new Short((short) 2);
|
||||||
|
final SymbolicPathNameTlv tlv1 = SymbolicPathNameTlv.of(value1, length1);
|
||||||
|
|
||||||
|
byte[] value2 = {0x41 };
|
||||||
|
Short length2 = new Short((short) 2);
|
||||||
|
final SymbolicPathNameTlv tlv2 = SymbolicPathNameTlv.of(value1, length2);
|
||||||
|
|
||||||
|
byte[] value3 = {0x41, 0x43 };
|
||||||
|
Short length3 = new Short((short) 3);
|
||||||
|
final SymbolicPathNameTlv tlv3 = SymbolicPathNameTlv.of(value3, length3);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void basics() {
|
||||||
|
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user