sunishvk
Committed by Gerrit Code Review

ONOS-4083,ONOS-4084:ISIS PDU TLV Data Structures

Change-Id: Ice0d42f2c886fa5f398b562e126614ed45f858a2
Showing 40 changed files with 2314 additions and 184 deletions
......@@ -37,7 +37,7 @@
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of adjacency state TLV of P2P neighbor.
*/
public class AdjacencyStateTlv extends TlvHeader implements IsisTlv {
private byte adjacencyType;
private int localCircuitId;
private String neighborSystemId;
private int neighborLocalCircuitId;
/**
* Creates an instance of adjacency state TLV..
*
* @param tlvHeader tlvHeader
*/
public AdjacencyStateTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns local circuit ID for adjacency state TLV.
*
* @return local circuit ID
*/
public int localCircuitId() {
return localCircuitId;
}
/**
* Sets local circuit ID for adjacency state TLV.
*
* @param localCircuitId local circuit Id
*/
public void setLocalCircuitId(int localCircuitId) {
this.localCircuitId = localCircuitId;
}
/**
* Returns neighbor system ID for adjacency state TLV.
*
* @return neighbor system ID
*/
public String neighborSystemId() {
return neighborSystemId;
}
/**
* Sets neighbor system ID for adjacency state TLV.
*
* @param neighborSystemId neighbor system ID
*/
public void setNeighborSystemId(String neighborSystemId) {
this.neighborSystemId = neighborSystemId;
}
/**
* Returns neighbor local circuit ID for adjacency state TLV.
*
* @return neighbor local circuit ID
*/
public int neighborLocalCircuitId() {
return neighborLocalCircuitId;
}
/**
* Sets neighbor local circuit ID for adjacency state TLV.
*
* @param neighborLocalCircuitId neighbor local circuit ID
*/
public void setNeighborLocalCircuitId(int neighborLocalCircuitId) {
this.neighborLocalCircuitId = neighborLocalCircuitId;
}
/**
* Returns adjacency type of adjacency state TLV.
*
* @return adjacency type
*/
public byte adjacencyType() {
return adjacencyType;
}
/**
* Sets adjacency type for adjacency state TLV.
*
* @param adjacencyType adjacency type
*/
public void setAdjacencyType(byte adjacencyType) {
this.adjacencyType = adjacencyType;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setAdjacencyType(channelBuffer.readByte());
if (channelBuffer.readableBytes() > 0) {
this.setLocalCircuitId(channelBuffer.readInt());
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setNeighborSystemId(IsisUtil.systemId(tempByteArray));
this.setNeighborLocalCircuitId(channelBuffer.readInt());
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns adjacency type TLV body as byte array.
*
* @return byteArray TLV body of area address TLV
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
bytes.add(this.adjacencyType);
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId)));
bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId));
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId)));
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("adjacencyType", adjacencyType)
.add("localCircuitId", localCircuitId)
.add("neighborSystemId", neighborSystemId)
.add("neighborLocalCircuitId", neighborLocalCircuitId)
.toString();
}
}
......@@ -13,52 +13,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Represents the area address TLV.
* Representation of area address TLV.
*/
public class AreaAddressTlv extends TlvHeader implements IsisTlv {
private List<String> areaAddress = new ArrayList();
private List<String> areaAddress = new ArrayList<>();
/**
* Sets TLV type and TLV length of area address TLV.
* Creates an instance of area address TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader tlvHeader
*/
public AreaAddressTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Adds the area address to the area address TLV.
*
* @param areaAddress area address
*/
public void addAddress(String areaAddress) {
this.areaAddress.add(areaAddress);
}
/**
* Gets the area address of area address TLV.
* Returns the area address of area address TLV.
*
* @return area address
* @return areaAddress area address
*/
public List<String> areaAddress() {
return this.areaAddress;
}
@Override
public void readFrom(ByteBuf byteBuf) {
while (byteBuf.readableBytes() > 0) {
int addressLength = byteBuf.readByte();
byte[] addressBytes = new byte[IsisUtil.THREE_BYTES];
byteBuf.readBytes(addressBytes, 0, IsisUtil.THREE_BYTES);
String areaAddress = IsisUtil.areaAddres(addressBytes);
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() > 0) {
int addressLength = channelBuffer.readByte();
byte[] addressbytes = new byte[addressLength];
channelBuffer.readBytes(addressbytes, 0, addressLength);
String areaAddress = IsisUtil.areaAddres(addressbytes);
this.areaAddress.add(areaAddress);
}
}
......@@ -66,38 +72,32 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv {
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Gets TLV body of area address TLV.
* Returns TLV body of area address TLV.
*
* @return byteArray TLV body of area address TLV
*/
public byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList();
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (String areaAddress : this.areaAddress) {
bytes.add((byte) (areaAddress.length() / 2));
bytes.addAll(IsisUtil.areaAddresToBytes(areaAddress));
}
byte[] byteArray = new byte[bytes.size()];
int i = 0;
for (byte byt : bytes) {
byteArray[i++] = byt;
bytes.addAll(IsisUtil.areaAddressToBytes(areaAddress));
}
return byteArray;
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("areaAddress", areaAddress)
.toString();
}
}
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* Representation of host name TLV.
*/
public class HostNameTlv extends TlvHeader {
private String hostName;
/**
* Creates an instance of host name TLV.
*
* @param tlvHeader tlvHeader.
*/
public HostNameTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns host name of host name TLV.
*
* @return host name
*/
public String hostName() {
return hostName;
}
/**
* Sets host name for host name TLV.
*
* @param hostName host name.
*/
public void setHostName(String hostName) {
this.hostName = hostName;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
byte[] addressbytes = new byte[this.tlvLength()];
channelBuffer.readBytes(addressbytes, 0, this.tlvLength());
this.hostName = new String(addressbytes);
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns TLV body of host name TLV.
*
* @return byteArray TLV body of host name TLV
*/
private byte[] tlvBodyAsBytes() {
byte[] bytes = this.hostName.getBytes();
return bytes;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("hostName", hostName)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* Representation of IDRP information TLV.
*/
public class IdrpInformationTlv extends TlvHeader implements IsisTlv {
private byte irdpInformationType;
private int externalInformation;
/**
* Creates an instance of IDRP information TLV.
*
* @param tlvHeader tlvHeader
*/
public IdrpInformationTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns the external information of IDRP information TLV.
*
* @return external information
*/
public int externalInformation() {
return externalInformation;
}
/**
* Sets the external information for IDRP information TLV.
*
* @param externalInformation external information
*/
public void setExternalInformation(int externalInformation) {
this.externalInformation = externalInformation;
}
/**
* Returns the IDRP information of IDRP information TLV.
*
* @return IDRP information type
*/
public byte irdpInformationType() {
return irdpInformationType;
}
/**
* Sets the IDRP information for IDRP information TLV.
*
* @param irdpInformationType IDRP information type
*/
public void setIrdpInformationType(byte irdpInformationType) {
this.irdpInformationType = irdpInformationType;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
//TODO
}
@Override
public byte[] asBytes() {
//TODO
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("externalInformation", externalInformation)
.add("irdpInformationType", irdpInformationType)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of IP extended reachability TLV.
*/
public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
private String sysIdAndPseudoNumber;
private int defaultMetric;
private byte subTlvLength;
private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
/**
* Creates an instance of IP external reachability TLV.
*
* @param tlvHeader tlvHeader
*/
public IpExtendedReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns the system ID and pseudo number of IP external reachability TLV.
*
* @return sysIdAndPseudoNumber system ID and pseudo number
*/
public String sysIdAndPseudoNumber() {
return sysIdAndPseudoNumber;
}
/**
* Sets the system ID and pseudo number for IP external reachability TLV.
*
* @param sysIdAndPseudoNumber system ID and pseudo number
*/
public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
}
/**
* Adds the traffic engineering sub TLV to IP external reachability TLV.
*
* @param trafEnginSubTlv traffic engineering sub TLV
*/
public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
this.trafEnginSubTlv.add(trafEnginSubTlv);
}
/**
* Returns the sub TLV length of IP external reachability TLV.
*
* @return sub TLV length
*/
public byte subTlvLength() {
return subTlvLength;
}
/**
* Sets the sub TLV length for IP external reachability TLV.
*
* @param subTlvLength sub TLV length
*/
public void setSubTlvLength(byte subTlvLength) {
this.subTlvLength = subTlvLength;
}
/**
* Returns default metric of IP external reachability TLV.
*
* @return default metric
*/
public int defaultMetric() {
return defaultMetric;
}
/**
* Sets default metric for IP external reachability TLV.
*
* @param defaultMetric default metric
*/
public void setDefaultMetric(int defaultMetric) {
this.defaultMetric = defaultMetric;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
this.setDefaultMetric(channelBuffer.readUnsignedMedium());
this.setSubTlvLength((byte) channelBuffer.readByte());
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readByte());
tlvHeader.setTlvLength(channelBuffer.readByte());
this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
channelBuffer.readBytes(tlvHeader.tlvLength())));
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
//systemID + pseudo number+length of subtlv=11l
tlvBody[10] = (byte) (tlvBody.length - 11);
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns TLV body of IP external reachability TLV.
*
* @return byteArray TLV body of IP external reachability TLV.
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bodyLst = new ArrayList<>();
bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
bodyLst.add(this.subTlvLength());
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
return Bytes.toArray(bodyLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
.add("defaultMetric", defaultMetric)
.add("subTlvLength", subTlvLength)
.add("trafEnginSubTlv", trafEnginSubTlv)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of IP external reachability TLV.
*/
public class IpExternalReachabilityTlv extends TlvHeader implements IsisTlv {
private String sysIdAndPseudoNumber;
private int defaultMetric;
private byte subTlvLength;
private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
/**
* Sets TLV type and TLV length for IP external reachability TLV.
*
* @param tlvHeader tlvHeader
*/
public IpExternalReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Gets the system ID and pseudo number of IP external reachability TLV.
*
* @return sysIdAndPseudoNumber system ID and pseudo number
*/
public String sysIdAndPseudoNumber() {
return sysIdAndPseudoNumber;
}
/**
* Gets the system ID and pseudo number for IP external reachability TLV.
*
* @param sysIdAndPseudoNumber system ID and pseudo number
*/
public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
}
/**
* Adds the traffic engineering sub TLV to IP external reachability TLV.
*
* @param trafEnginSubTlv traffic engineering sub TLV
*/
public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
this.trafEnginSubTlv.add(trafEnginSubTlv);
}
/**
* Gets the sub TLV length of IP external reachability TLV.
*
* @return sub TLV length
*/
public byte subTlvLength() {
return subTlvLength;
}
/**
* Sets the sub TLV length for IP external reachability TLV.
*
* @param subTlvLength sub TLV length
*/
public void setSubTlvLength(byte subTlvLength) {
this.subTlvLength = subTlvLength;
}
/**
* Gets default metric of IP external reachability TLV.
*
* @return default metric
*/
public int defaultMetric() {
return defaultMetric;
}
/**
* Sets default metric for IP external reachability TLV.
*
* @param defaultMetric default metric
*/
public void setDefaultMetric(int defaultMetric) {
this.defaultMetric = defaultMetric;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setSysIdAndPseudoNumber(IsisUtil.systemIdPlus(tempByteArray));
this.setDefaultMetric(channelBuffer.readUnsignedMedium());
this.setSubTlvLength((byte) channelBuffer.readByte());
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readByte());
tlvHeader.setTlvLength(channelBuffer.readByte());
this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
channelBuffer.readBytes(tlvHeader.tlvLength())));
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
//systemID + pseudo number+length of subtlv=11l
tlvBody[10] = (byte) (tlvBody.length - 11);
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Gets TLV body of IP external reachability TLV.
*
* @return byteArray TLV body of IP external reachability TLV.
*/
public byte[] tlvBodyAsBytes() {
List<Byte> bodyLst = new ArrayList<>();
bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sysIdAndPseudoNumber()));
bodyLst.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.defaultMetric())));
bodyLst.add(this.subTlvLength());
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
return Bytes.toArray(bodyLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
.add("defaultMetric", defaultMetric)
.add("subTlvLength", subTlvLength)
.toString();
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.isis.io.util.IsisUtil;
......@@ -25,13 +25,14 @@ import java.util.ArrayList;
import java.util.List;
/**
* Represents IP interface address TLV.
* Representation of IP interface address TLV.
*/
public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
private List<Ip4Address> interfaceAddress = new ArrayList();
private List<Ip4Address> interfaceAddress = new ArrayList<>();
/**
* Sets TLV type and TLV length of IP interface address TLV.
* Creates an instance of IP interface address TLV.
*
* @param tlvHeader tlvHeader.
*/
......@@ -43,58 +44,60 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
}
/**
* Gets interface address of interface address TLV.
* Adds the interface address to IP interface address TLV.
*
* @param interfaceAddress interface address
*/
public void addInterfaceAddres(Ip4Address interfaceAddress) {
this.interfaceAddress.add(interfaceAddress);
}
/**
* Returns the interface address of IP interface address TLV.
*
* @return interfaceAddress interface address
* @return interface address
*/
public List<Ip4Address> interfaceAddress() {
return interfaceAddress;
}
@Override
public void readFrom(ByteBuf byteBuf) {
while (byteBuf.readableBytes() >= 4) {
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() >= 4) {
byte[] addressbytes = new byte[IsisUtil.FOUR_BYTES];
byteBuf.readBytes(addressbytes, 0, IsisUtil.FOUR_BYTES);
channelBuffer.readBytes(addressbytes, 0, IsisUtil.FOUR_BYTES);
this.interfaceAddress.add(Ip4Address.valueOf(addressbytes));
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Gets TLV body of interface address TLV.
* Returns TLV body of IP interface address TLV.
*
* @return byteArray TLV body of interface address TLV.
* @return byteArray TLV body of IP interface address TLV
*/
public byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList();
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (Ip4Address ip4Address : this.interfaceAddress) {
bytes.addAll(Bytes.asList(ip4Address.toOctets()));
}
byte[] byteArray = new byte[bytes.size()];
int i = 0;
for (byte byt : bytes) {
byteArray[i++] = byt;
}
return byteArray;
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("interfaceAddress", interfaceAddress)
.toString();
}
}
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of IP internal reachability TLV.
*/
public class IpInternalReachabilityTlv extends TlvHeader implements IsisTlv {
private List<MetricOfInternalReachability> metricOfInternalReachability = new ArrayList<>();
/**
* Creates an instance of IP internal reachability TLV.
*
* @param tlvHeader tlvHeader.
*/
public IpInternalReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Adds the metric of internal reachability to internal reachability TLV.
*
* @param metricValue metric of internal reachability
*/
public void addInternalReachabilityMetric(MetricOfInternalReachability metricValue) {
this.metricOfInternalReachability.add(metricValue);
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() > 0) {
MetricOfInternalReachability metricOfInternalReachability = new MetricOfInternalReachability();
metricOfInternalReachability.readFrom(channelBuffer);
this.metricOfInternalReachability.add(metricOfInternalReachability);
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns TLV body of internal reachability TLV.
*
* @return byteArray TLV body of area address TLV
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (MetricOfInternalReachability metricOfInternalReachability :
this.metricOfInternalReachability) {
bytes.addAll(Bytes.asList(metricOfInternalReachability.asBytes()));
}
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("metricOfInternalReachability", metricOfInternalReachability)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of IS reachability TLV.
*/
public class IsReachabilityTlv extends TlvHeader {
private int reserved;
private List<MetricsOfReachability> metricsOfReachabilities = new ArrayList<>();
/**
* Creates an instance of IS reachability TLV.
*
* @param tlvHeader tlvHeader.
*/
public IsReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns the reserved value of IS reachability TLV.
*
* @return reserved
*/
public int reserved() {
return reserved;
}
/**
* Sets the reserved value for IS reachability TLV.
*
* @param reserved reserved
*/
public void setReserved(int reserved) {
this.reserved = reserved;
}
/**
* Adds the metric of reachability to IS reachability TLV..
*
* @param metricsOfReachability metric of reachability
*/
public void addMeticsOfReachability(MetricsOfReachability metricsOfReachability) {
this.metricsOfReachabilities.add(metricsOfReachability);
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setReserved(channelBuffer.readByte());
while (channelBuffer.readableBytes() > 0) {
MetricsOfReachability metricsOfReachability = new MetricsOfReachability();
metricsOfReachability.readFrom(channelBuffer);
this.metricsOfReachabilities.add(metricsOfReachability);
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns TLV body of IS reachability TLV.
*
* @return byteArray TLV body of area address TLV
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
bytes.add((byte) this.reserved());
for (MetricsOfReachability metricsOfReachability : this.metricsOfReachabilities) {
bytes.addAll(Bytes.asList(metricsOfReachability.asBytes()));
}
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("metricsOfReachabilities", metricsOfReachabilities)
.toString();
}
}
......@@ -17,7 +17,7 @@ package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.MacAddress;
import org.onosproject.isis.io.util.IsisUtil;
......@@ -25,78 +25,77 @@ import java.util.ArrayList;
import java.util.List;
/**
* Represents ISIS neighbor TLV.
* Representation of ISIS neighbor TLV.
*/
public class IsisNeighborTlv extends TlvHeader implements IsisTlv {
private List<MacAddress> neighbor = new ArrayList();
private List<MacAddress> neighbor = new ArrayList<>();
/**
* Sets TLV type and TLV length of ISIS neighbor TLV.
* Creates an instance of ISIS neighbor TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader tlvHeader
*/
public IsisNeighborTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Adds the MAC address of the neighbor to ISIS neighbor TLV.
*
* @param macAddress MAC address
*/
public void addNeighbor(MacAddress macAddress) {
neighbor.add(macAddress);
}
/**
* Gets the MAC address of the neighbor TLV.
* Returns the MAC address of the ISIS neighbor TLV.
*
* @return neighbor MAC address of the neighbor TLV
* @return neighbor
*/
public List<MacAddress> neighbor() {
return this.neighbor;
}
@Override
public void readFrom(ByteBuf byteBuf) {
while (byteBuf.readableBytes() >= 6) {
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() >= 6) {
byte[] addressbytes = new byte[IsisUtil.SIX_BYTES];
byteBuf.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES);
channelBuffer.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES);
this.neighbor.add(MacAddress.valueOf(addressbytes));
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Gets TLV body of neighbor TLV.
* Returns TLV body of ISIS neighbor TLV.
*
* @return byteArray TLV body of neighbor TLV
* @return byteArray TLV body of area address TLV
*/
public byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList();
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (MacAddress macAddress : this.neighbor) {
bytes.addAll(Bytes.asList(macAddress.toBytes()));
}
byte[] byteArray = new byte[bytes.size()];
int i = 0;
for (byte byt : bytes) {
byteArray[i++] = byt;
}
return byteArray;
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("neighbor", neighbor)
.toString();
}
}
\ No newline at end of file
......
......@@ -16,7 +16,7 @@
package org.onosproject.isis.io.isispacket.tlv;
/**
* Represents ISIS TLV.
* Representation of ISIS TLV.
*/
public interface IsisTlv {
}
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of LSP entries TLV.
*/
public class LspEntriesTlv extends TlvHeader implements IsisTlv {
private List<LspEntry> lspEntryList = new ArrayList<>();
/**
* Creates an instance of LSP entries TLV.
*
* @param tlvHeader tlvHeader.
*/
public LspEntriesTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
this.setTlvLength(tlvHeader.tlvLength());
}
/**
* Returns the LSP entry of LSP entries TLV.
*
* @return LSP entries
*/
public List<LspEntry> lspEntry() {
return lspEntryList;
}
/**
* Adds the the LSP entry to LSP entries TLV.
*
* @param lspEntry LSP entry
*/
public void addLspEntry(LspEntry lspEntry) {
this.lspEntryList.add(lspEntry);
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() >= 16) {
LspEntry lspEntry = new LspEntry();
lspEntry.readFrom(channelBuffer.readBytes(16));
lspEntryList.add(lspEntry);
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Returns TLV body of LSP entries TLV.
*
* @return byteArray TLV body of LSP entries TLV
*/
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (LspEntry lspEntry : lspEntryList) {
bytes.addAll(Bytes.asList(lspEntry.lspEntryAsBytes()));
}
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("lspEntryList", lspEntryList)
.toString();
}
}
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of LSP entry.
*/
public class LspEntry {
private int lspSequenceNumber;
private int lspChecksum;
private int remainingTime;
private String lspId;
/**
* Returns LSP sequence number of LSP entry.
*
* @return LSP sequence number
*/
public int lspSequenceNumber() {
return lspSequenceNumber;
}
/**
* Sets LSP sequenceNumber for LSP entry.
*
* @param lspSequenceNumber lspSequenceNumber.
*/
public void setLspSequenceNumber(int lspSequenceNumber) {
this.lspSequenceNumber = lspSequenceNumber;
}
/**
* Returns LSP checksum of LSP entry.
*
* @return LSP checksum
*/
public int lspChecksum() {
return lspChecksum;
}
/**
* Sets LSP checksum for LSP entry.
*
* @param lspChecksum LSP checksum
*/
public void setLspChecksum(int lspChecksum) {
this.lspChecksum = lspChecksum;
}
/**
* Returns remaining time of LSP entry.
*
* @return remaining time
*/
public int remainingTime() {
return remainingTime;
}
/**
* Sets remaining time for LSP entry.
*
* @param remainingTime remaining time
*/
public void setRemainingTime(int remainingTime) {
this.remainingTime = remainingTime;
}
/**
* Returns LSP ID of LSP entry.
*
* @return LSP ID
*/
public String lspId() {
return lspId;
}
/**
* Sets LSP ID for LSp entry.
*
* @param lspId LSP ID
*/
public void setLspId(String lspId) {
this.lspId = lspId;
}
/**
* Sets the LSP entry values for LSP entry from byte buffer.
*
* @param channelBuffer channel Buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
this.setRemainingTime(channelBuffer.readUnsignedShort());
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setLspId(IsisUtil.systemIdPlus(tempByteArray));
this.setLspSequenceNumber(channelBuffer.readInt());
this.setLspChecksum(channelBuffer.readUnsignedByte());
}
/**
* Returns LSP entry values as bytes of LSP entry.
*
* @return byteArray LSP entry values as bytes of LSP entry
*/
public byte[] lspEntryAsBytes() {
List<Byte> bytes = new ArrayList<>();
bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.remainingTime())));
bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.lspId()));
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.lspSequenceNumber())));
bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.lspChecksum())));
return Bytes.toArray(bytes);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("lspSequenceNumber", lspSequenceNumber)
.add("lspChecksum", lspChecksum)
.add("remainingTime", remainingTime)
.add("lspId", lspId)
.toString();
}
}
\ No newline at end of file
......@@ -17,19 +17,19 @@ package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Represents padding TLV.
* Representation of padding TLV.
*/
public class PaddingTlv extends TlvHeader implements IsisTlv {
private List<Byte> paddings = new ArrayList();
private List<Byte> paddings = new ArrayList<>();
/**
* Sets TLV type and TLV length of padding TLV.
* Creates an instance of padding TLV.
*
* @param tlvHeader tlvHeader.
*/
......@@ -39,9 +39,9 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
}
@Override
public void readFrom(ByteBuf byteBuf) {
while (byteBuf.readableBytes() > 0) {
this.paddings.add(byteBuf.readByte());
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() > 0) {
this.paddings.add(channelBuffer.readByte());
}
}
......@@ -51,17 +51,18 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
/**
* Gets TLV body padding TLV.
* Returns TLV body of padding TLV.
*
* @return areaArea TLV body padding TLV\\
* @return byteArray TLV body of padding TLV
*/
public byte[] tlvBodyAsBytes() {
private byte[] tlvBodyAsBytes() {
byte[] areaArea = new byte[this.tlvLength()];
return areaArea;
}
......@@ -70,6 +71,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("paddings", paddings)
.toString();
}
}
\ No newline at end of file
......
......@@ -15,21 +15,22 @@
*/
package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Represents Protocol supported TLV.
* Representation of protocol supported TLV.
*/
public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
private List<Byte> protocolSupported = new ArrayList();
private List<Byte> protocolSupported = new ArrayList<>();
/**
* Sets TLV type and TLV length of protocol supported TLV.
* Creates an instance of protocol supported TLV.
*
* @param tlvHeader tlvHeader.
*/
......@@ -41,21 +42,27 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
}
/**
* Gets the Protocol Supported by the TLV.
* Adds the protocol supported to protocol supported TLV.
*
* @return Protocol Supported
* @param protocolValue protocol supported
*/
public List<Byte> protocolSupported() {
public void addProtocolSupported(byte protocolValue) {
protocolSupported.add(protocolValue);
}
/**
* Returns protocols supported of protocol supported TLV.
*
* @return protocol supported
*/
public List<Byte> protocolSupported() {
return this.protocolSupported;
}
@Override
public void readFrom(ByteBuf byteBuf) {
while (byteBuf.readableBytes() > 0) {
this.protocolSupported.add(byteBuf.readByte());
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() > 0) {
this.protocolSupported.add(channelBuffer.readByte());
}
}
......@@ -65,8 +72,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
byte[] tlvHeader = tlvHeaderAsByteArray();
byte[] tlvBody = tlvBodyAsBytes();
tlvHeader[1] = (byte) tlvBody.length;
bytes = Bytes.concat(tlvHeader, tlvBody);
return bytes;
}
......@@ -75,9 +82,8 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
*
* @return byteArray TLV body of protocol supported TLV
*/
public byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList();
private byte[] tlvBodyAsBytes() {
List<Byte> bytes = new ArrayList<>();
for (byte byt : this.protocolSupported) {
bytes.add(byt);
}
......@@ -88,4 +94,12 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
}
return byteArray;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("protocolSupported", protocolSupported)
.toString();
}
}
\ No newline at end of file
......
......@@ -15,55 +15,90 @@
*/
package org.onosproject.isis.io.isispacket.tlv;
import io.netty.buffer.ByteBuf;
import org.onosproject.isis.io.util.IsisUtil;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* Represents TLV finder.
* Representation of TLV Finder.
*/
public class TlvFinder extends TlvHeader {
/**
* Sets the value for TLV header and the body of the TLV.
* Sets the value for TLV header.
*
* @param tlvHeader tlvHeader
* @param byteBuf byteBuf
* @return isisTlv ISIS TLV
* @param tlvHeader tlvHeader
* @param channelBuffer byteBuf
* @return isisTlv
*/
public static IsisTlv findTlv(TlvHeader tlvHeader, ByteBuf byteBuf) {
public static IsisTlv findTlv(TlvHeader tlvHeader, ChannelBuffer channelBuffer) {
IsisTlv isisTlv = null;
switch (tlvHeader.tlvType()) {
case IsisUtil.AREAADDRESS:
switch (TlvType.get(tlvHeader.tlvType())) {
case AREAADDRESS:
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.readFrom(byteBuf);
areaAddressTlv.readFrom(channelBuffer);
isisTlv = areaAddressTlv;
break;
case IsisUtil.IPINTERFACEADDRESS:
case AUTHENTICATION:
//TODO
break;
case EXTENDEDISREACHABILITY:
//TODO
break;
case IDRPINFORMATION:
IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader);
idrpInformationTlv.readFrom(channelBuffer);
isisTlv = idrpInformationTlv;
break;
case IPEXTENDEDREACHABILITY:
IpExtendedReachabilityTlv iperTlv = new IpExtendedReachabilityTlv(tlvHeader);
iperTlv.readFrom(channelBuffer);
isisTlv = iperTlv;
break;
case IPINTERFACEADDRESS:
IpInterfaceAddressTlv ipTlv = new IpInterfaceAddressTlv(tlvHeader);
ipTlv.readFrom(byteBuf);
ipTlv.readFrom(channelBuffer);
isisTlv = ipTlv;
break;
case IsisUtil.PROTOCOLSUPPORTED:
case IPINTERNALREACHABILITY:
IpInternalReachabilityTlv iprTlv = new IpInternalReachabilityTlv(tlvHeader);
iprTlv.readFrom(channelBuffer);
isisTlv = iprTlv;
break;
case ISALIAS:
break;
case PROTOCOLSUPPORTED:
ProtocolSupportedTlv psTlv = new ProtocolSupportedTlv(tlvHeader);
psTlv.readFrom(byteBuf);
psTlv.readFrom(channelBuffer);
isisTlv = psTlv;
break;
case IsisUtil.ISNEIGHBORS:
case ISREACHABILITY:
IsReachabilityTlv isrTlv = new IsReachabilityTlv(tlvHeader);
isrTlv.readFrom(channelBuffer);
isisTlv = isrTlv;
break;
case ISNEIGHBORS:
IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
isisNeighborTlv.readFrom(byteBuf);
isisNeighborTlv.readFrom(channelBuffer);
isisTlv = isisNeighborTlv;
break;
case IsisUtil.PADDING:
case LSPENTRY:
LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
lspEntriesTlv.readFrom(channelBuffer);
isisTlv = lspEntriesTlv;
break;
case PADDING:
PaddingTlv paddingTlv = new PaddingTlv(tlvHeader);
paddingTlv.readFrom(byteBuf);
paddingTlv.readFrom(channelBuffer);
isisTlv = paddingTlv;
break;
case ADJACENCYSTATE:
AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
adjacencyStateTlv.readFrom(channelBuffer);
isisTlv = adjacencyStateTlv;
break;
default:
break;
}
return isisTlv;
}
}
\ No newline at end of file
......
......@@ -17,29 +17,29 @@ package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* Represents TLV header.
* Representation of TLV header.
*/
public class TlvHeader implements IsisTlv {
private int tlvType;
private int tlvLength;
/**
* Gets the TLV length of the TLV.
* Returns TLV length of TLV.
*
* @return tlvLength TLV length
* @return TLV length
*/
public int tlvLength() {
return tlvLength;
}
/**
* Sets the TLV length for the mTLV.
* Sets TLV length for TLV.
*
* @param tlvLength TLV length
*/
......@@ -48,16 +48,16 @@ public class TlvHeader implements IsisTlv {
}
/**
* Gets the TLV type of the TLV.
* Returns TLV type of TLV.
*
* @return tlvType TLV type
* @return TLV type
*/
public int tlvType() {
return tlvType;
}
/**
* Sets TLV type for the TLV.
* Sets TLV type for TLV.
*
* @param tlvType TLV type
*/
......@@ -66,32 +66,31 @@ public class TlvHeader implements IsisTlv {
}
/**
* Sets the TLV values of TLV from b yte buffer.
* Sets TLV values from channel buffer.
*
* @param byteBuf byteBuf.
* @param channelBuffer channel Buffer instance
*/
public void readFrom(ByteBuf byteBuf) {
public void readFrom(ChannelBuffer channelBuffer) {
//implemented in sub classes
}
/**
* Gets the TLV of the TLV as bytes.
* Returns TLV as byte array.
*
* @return null
* @return byteArray TLV body of area address TLV
*/
public byte[] asBytes() {
//implemented the subclasses
return null;
}
/**
* Gets the TLV header of the TLV.
* Returns TLV header of TLV as bytes.
*
* @return headerLst TLV of the TLV
* @return TLV header as bytes
*/
public byte[] tlvHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList();
List<Byte> headerLst = new ArrayList<>();
headerLst.add((byte) this.tlvType);
headerLst.add((byte) this.tlvLength);
return Bytes.toArray(headerLst);
......
......@@ -15,8 +15,12 @@
*/
package org.onosproject.isis.io.isispacket.tlv;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Represents various values for TLV types.
* Representation of various values for TLV types.
*/
public enum TlvType {
AREAADDRESS(1),
......@@ -25,19 +29,32 @@ public enum TlvType {
PADDING(8),
LSPENTRY(9),
AUTHENTICATION(10),
CHECKSUM(12),
HOSTNAME(137),
EXTENDEDISREACHABILITY(22),
ISALIAS(24),
IPINTERNALREACHABILITY(128),
PROTOCOLSUPPORTED(129),
IPEXTERNALREACHABILITY(130),
IPEXTENDEDREACHABILITY(135),
IDRPINFORMATION(131),
IPINTERFACEADDRESS(132);
IPINTERFACEADDRESS(132),
ADJACENCYSTATE(240);
// Reverse lookup table
private static final Map<Integer, TlvType> LOOKUP = new HashMap<>();
// Populate the lookup table on loading time
static {
for (TlvType isisTlvType : EnumSet.allOf(TlvType.class)) {
LOOKUP.put(isisTlvType.value(), isisTlvType);
}
}
private int value;
/**
* Sets the TLV type value.
*
* @param value value.
*/
TlvType(int value) {
......@@ -45,10 +62,21 @@ public enum TlvType {
}
/**
* Gets the enum instance from type value - reverse lookup purpose.
*
* @param tlvTypeValue TLV type value
* @return ISIS TLV type instance
*/
public static TlvType get(int tlvTypeValue) {
return LOOKUP.get(tlvTypeValue);
}
/**
* Gets value.
*
* @return value
*/
public int value() {
return value;
}
}
}
\ No newline at end of file
......
......@@ -16,23 +16,33 @@
package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.primitives.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Represents conversion of TLV's to bytes.
* Representation of conversion of TLV's to bytes.
*/
public final class TlvsToBytes {
protected static final Logger log = LoggerFactory.getLogger(TlvsToBytes.class);
/**
* Creates an instance.
*/
private TlvsToBytes() {
}
/**
* Sets the ISIS TLV and returns in the form of bytes.
*
* @param isisTlv isisTlv
* @return tlvBytes TLV bytes
* @param isisTlv isisTlv.
* @return tlvBytes
*/
public static List<Byte> tlvToBytes(IsisTlv isisTlv) {
List<Byte> tlvBytes = new ArrayList();
List<Byte> tlvBytes = new ArrayList<>();
if (isisTlv instanceof AreaAddressTlv) {
AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes()));
......@@ -48,16 +58,33 @@ public final class TlvsToBytes {
} else if (isisTlv instanceof IsisNeighborTlv) {
IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes()));
} else if (isisTlv instanceof AdjacencyStateTlv) {
AdjacencyStateTlv isisAdjacencyState
= (AdjacencyStateTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(isisAdjacencyState.asBytes()));
} else if (isisTlv instanceof HostNameTlv) {
HostNameTlv hostNameTlv
= (HostNameTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(hostNameTlv.asBytes()));
} else if (isisTlv instanceof IpExtendedReachabilityTlv) {
IpExtendedReachabilityTlv ipExtendedReachabilityTlv
= (IpExtendedReachabilityTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(ipExtendedReachabilityTlv.asBytes()));
} else if (isisTlv instanceof IpInternalReachabilityTlv) {
IpInternalReachabilityTlv ipInternalReachabilityTlv
= (IpInternalReachabilityTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(ipInternalReachabilityTlv.asBytes()));
} else if (isisTlv instanceof IsReachabilityTlv) {
IsReachabilityTlv isReachabilityTlv
= (IsReachabilityTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(isReachabilityTlv.asBytes()));
} else if (isisTlv instanceof LspEntriesTlv) {
LspEntriesTlv lspEntriesTlv
= (LspEntriesTlv) isisTlv;
tlvBytes.addAll(Bytes.asList(lspEntriesTlv.asBytes()));
} else {
System.out.println("UNKNOWN TLV TYPE ::TlvsToBytes ");
log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
}
return tlvBytes;
}
/**
* Creates an instance.
*/
private TlvsToBytes() {
//private constructor
}
}
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
/**
* Representation of an administrative group.
*/
public class AdministrativeGroup extends TlvHeader implements TrafficEngineeringSubTlv {
private int administrativeGroup;
/**
* Creates an administrative group instance.
*
* @param header Tlv Header instance
*/
public AdministrativeGroup(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Gets administrative group value.
*
* @return administrative group value
*/
public int administrativeGroup() {
return administrativeGroup;
}
/**
* Sets administrative group value.
*
* @param administrativeGroup value
*/
public void setAdministrativeGroup(int administrativeGroup) {
this.administrativeGroup = administrativeGroup;
}
/**
* Gets administrative group value.
*
* @return administrativeGroup value
*/
public int getAdministrativeGroupValue() {
return this.administrativeGroup;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer Channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[tlvLength()];
channelBuffer.readBytes(tempByteArray, 0, tlvLength());
this.setAdministrativeGroup(IsisUtil.byteToInteger(tempByteArray));
}
/**
* Returns administrative group as byte array.
*
* @return administrative group instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets administrative group body as byte array.
*
* @return byte array of sub tlv administrative group
*/
public byte[] tlvBodyAsBytes() {
byte[] linkSubTypeBody;
linkSubTypeBody = IsisUtil.convertToFourBytes(this.administrativeGroup);
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("administrativeGroup", administrativeGroup)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
/**
* Representation of maximum bandwidth TE value.
*/
public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
private float maximumBandwidth;
/**
* Creates an instance of maximum bandwidth.
*
* @param header tlv header instance
*/
public MaximumBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Sets value of maximum bandwidth.
*
* @param maximumBandwidth value of maximum bandwidth
*/
public void setMaximumBandwidth(float maximumBandwidth) {
this.maximumBandwidth = maximumBandwidth;
}
/**
* Gets value of maximum bandwidth.
*
* @return maximumBandwidth value of maximum bandwidth
*/
public float getMaximumBandwidthValue() {
return this.maximumBandwidth;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[tlvLength()];
channelBuffer.readBytes(tempByteArray, 0, tlvLength());
int maxBandwidth = (IsisUtil.byteToInteger(tempByteArray));
this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
}
/**
* Gets byte array of maximum bandwidth sub tlv.
*
* @return byte array of maximum bandwidth sub tlv
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets maximum bandwidth sub tlv byte array.
*
* @return byte array of maximum bandwidth sub tlv
*/
public byte[] tlvBodyAsBytes() {
byte[] linkSubTypeBody;
linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth));
return linkSubTypeBody;
}
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("maximumBandwidth", maximumBandwidth)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
/**
* Representation of maximum reservable bandwidth TE value.
*/
public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
private float maximumReservableBandwidth;
/**
* Creates an instance of maximum reservable bandwidth.
*
* @param header tlv header
*/
public MaximumReservableBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Sets value of maximum reversible bandwidth.
*
* @param maximumBandwidth maximum reversible bandwidth
*/
public void setMaximumBandwidth(float maximumBandwidth) {
this.maximumReservableBandwidth = maximumBandwidth;
}
/**
* Gets value of maximum reversible bandwidth.
*
* @return maximumBandwidth maximum reversible bandwidth
*/
public float getMaximumBandwidthValue() {
return this.maximumReservableBandwidth;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[tlvLength()];
channelBuffer.readBytes(tempByteArray, 0, tlvLength());
int maxBandwidth = (IsisUtil.byteToInteger(tempByteArray));
this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
}
/**
* Returns byte array of maximum reservable bandwidth.
*
* @return byte array of maximum reservable bandwidth
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets maximum reservable bandwidth sub tlv body as byte array.
*
* @return byte of maximum reservable bandwidth sub tlv body
*/
public byte[] tlvBodyAsBytes() {
byte[] linkSubTypeBody;
linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumReservableBandwidth));
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("maximumReservableBandwidth", maximumReservableBandwidth)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
/**
* Representation of sub tlv finder.
*/
public final class SubTlvFinder {
/**
* Creates an instance.
*/
private SubTlvFinder() {
}
/**
* Sets the value for TLV header and to find sub TLV and populate.
*
* @param tlvHeader tlvHeader
* @param channelBuffer byteBuf
* @return subTlv traffic engineering sub tlv
*/
public static TrafficEngineeringSubTlv findSubTlv(TlvHeader tlvHeader, ChannelBuffer channelBuffer) {
TrafficEngineeringSubTlv subTlv = null;
switch (SubTlvType.get(tlvHeader.tlvType())) {
case ADMINISTRATIVEGROUP:
AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
administrativeGroup.readFrom(channelBuffer);
subTlv = administrativeGroup;
break;
case MAXIMUMBANDWIDTH:
MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
maximumBandwidth.readFrom(channelBuffer);
subTlv = maximumBandwidth;
break;
case MAXIMUMRESERVABLEBANDWIDTH:
MaximumReservableBandwidth maxResBandwidth = new MaximumReservableBandwidth(tlvHeader);
maxResBandwidth.readFrom(channelBuffer);
subTlv = maxResBandwidth;
break;
case TRAFFICENGINEERINGMETRIC:
TrafficEngineeringMetric teMetric = new TrafficEngineeringMetric(tlvHeader);
teMetric.readFrom(channelBuffer);
subTlv = teMetric;
break;
case UNRESERVEDBANDWIDTH:
UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
unreservedBandwidth.readFrom(channelBuffer);
subTlv = unreservedBandwidth;
break;
default:
//TODO
break;
}
return subTlv;
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.primitives.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of conversion of TLV's to bytes.
*/
public final class SubTlvToBytes {
protected static final Logger log = LoggerFactory.getLogger(SubTlvToBytes.class);
/**
* Creates an instance.
*/
private SubTlvToBytes() {
//private constructor
}
/**
* Sets the ISIS sub TLV and returns in the form of bytes.
*
* @param subTlv isisTlv.
* @return subTlvBytes
*/
public static List<Byte> tlvToBytes(TrafficEngineeringSubTlv subTlv) {
List<Byte> subTlvBytes = new ArrayList<>();
if (subTlv instanceof AdministrativeGroup) {
AdministrativeGroup administrativeGroup = (AdministrativeGroup) subTlv;
subTlvBytes.addAll(Bytes.asList(administrativeGroup.asBytes()));
} else if (subTlv instanceof MaximumBandwidth) {
MaximumBandwidth maximumBandwidth = (MaximumBandwidth) subTlv;
subTlvBytes.addAll(Bytes.asList(maximumBandwidth.asBytes()));
} else if (subTlv instanceof MaximumReservableBandwidth) {
MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) subTlv;
subTlvBytes.addAll(Bytes.asList(maximumReservableBandwidth.asBytes()));
} else if (subTlv instanceof TrafficEngineeringMetric) {
TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) subTlv;
subTlvBytes.addAll(Bytes.asList(trafficEngineeringMetric.asBytes()));
} else if (subTlv instanceof UnreservedBandwidth) {
UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) subTlv;
subTlvBytes.addAll(Bytes.asList(unreservedBandwidth.asBytes()));
} else {
log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
}
return subTlvBytes;
}
}
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Representation of sub tlv type.
*/
public enum SubTlvType {
ADMINISTRATIVEGROUP(9),
MAXIMUMBANDWIDTH(6),
MAXIMUMRESERVABLEBANDWIDTH(7),
TRAFFICENGINEERINGMETRIC(5),
UNRESERVEDBANDWIDTH(8);
// Reverse lookup table
private static final Map<Integer, SubTlvType> LOOKUP = new HashMap<>();
// Populate the lookup table on loading time
static {
for (SubTlvType subTlvType : EnumSet.allOf(SubTlvType.class)) {
LOOKUP.put(subTlvType.value(), subTlvType);
}
}
private int value;
/**
* Sets the sub TLV type value.
*
* @param value value.
*/
SubTlvType(int value) {
this.value = value;
}
/**
* Gets the enum instance from type value - reverse lookup purpose.
*
* @param subTlvTypeValue TLV type value
* @return ISIS sub TLV type instance
*/
public static SubTlvType get(int subTlvTypeValue) {
return LOOKUP.get(subTlvTypeValue);
}
/**
* Gets value.
*
* @return value
*/
public int value() {
return value;
}
}
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
/**
* Representation of traffic engineering metric TE value.
*/
public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngineeringSubTlv {
private long trafficEngineeringMetric;
/**
* Creates an instance of traffic engineering metric .
*
* @param header tlv header instance
*/
public TrafficEngineeringMetric(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Sets TE metric value.
*
* @param trafficEngineeringMetric value of trafficEngineeringMetric
*/
public void setTrafficEngineeringMetric(long trafficEngineeringMetric) {
this.trafficEngineeringMetric = trafficEngineeringMetric;
}
/**
* Gets TE metric value.
*
* @return value of traffic engineering metric
*/
public long getTrafficEngineeringMetricValue() {
return this.trafficEngineeringMetric;
}
/**
* Reads bytes from channel buffer .
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[tlvLength()];
channelBuffer.readBytes(tempByteArray, 0, tlvLength());
this.setTrafficEngineeringMetric(IsisUtil.byteToLong(tempByteArray));
}
/**
* Gets instance as byte array.
*
* @return instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets trafficEngineeringMetric as byte array .
*
* @return byte array of trafficEngineeringMetric
*/
public byte[] tlvBodyAsBytes() {
byte[] linkSubTypeBody;
linkSubTypeBody = IsisUtil.convertToFourBytes(this.trafficEngineeringMetric);
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("trafficEngineeringMetric", trafficEngineeringMetric)
.toString();
}
}
\ No newline at end of file
......@@ -14,28 +14,10 @@
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket;
package org.onosproject.isis.io.isispacket.tlv.subtlv;
/**
* Represents ISIS constant parameters.
* Representation of traffic engineering sub tlv.
*/
public final class IsisConstantParameters {
public static final int IRPDISCRIMINATOR = 131;
public static final int PROOCOLID = 1;
public static final int VERSION = 1;
public static final int RESERVED = 0;
public static final int MAXAREAADDRESS = 3;
public static final int IDLENGTH = 6;
public static final int PROTOCOLSUPPORTED = 6;
public static final int PACKETMINIMUMLENGTH = 27;
public static final int PDULENGTHPOSITION = 17;
public static final int PDUHEADERFORREADFROM = 8;
/**
* Creates an instance of this class.
*/
private IsisConstantParameters() {
}
}
public interface TrafficEngineeringSubTlv {
}
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an unreserved band width TE value.
*/
public class UnreservedBandwidth extends TlvHeader implements TrafficEngineeringSubTlv {
private List<Float> unReservedBandwidth = new ArrayList<>();
/**
* Creates an instance of unreserved band width.
*
* @param header tlv header instance
*/
public UnreservedBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Adds value of un reserved bandwidth .
*
* @param unreservedBandwidth value of un reserved bandwidth
*/
public void addUnReservedBandwidth(float unreservedBandwidth) {
this.unReservedBandwidth.add(unreservedBandwidth);
}
/**
* Gets list of un reserved bandwidth .
*
* @return List of un reserved bandwidth
*/
public List<Float> getUnReservedBandwidthValue() {
return this.unReservedBandwidth;
}
/**
* Reads bytes from channel buffer .
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() >= IsisUtil.FOUR_BYTES) {
int maxReversibleBandwidth = channelBuffer.readInt();
this.addUnReservedBandwidth(Float.intBitsToFloat(maxReversibleBandwidth));
}
}
/**
* Gets instance as byte array.
*
* @return instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets unreserved bandwidth as byte array.
*
* @return unreserved bandwidth as byte array
*/
public byte[] tlvBodyAsBytes() {
List<Byte> linkSubTypeBody = new ArrayList<>();
if (this.unReservedBandwidth.size() < 8) {
int size = IsisUtil.EIGHT_BYTES - this.unReservedBandwidth.size();
for (int i = 0; i < size; i++) {
linkSubTypeBody.addAll(Bytes.asList(IsisUtil.convertToFourBytes(IsisUtil.INITIAL_BANDWIDTH)));
}
}
for (Float unreservedBandwidth : this.unReservedBandwidth) {
int unresBandwidth = Float.floatToIntBits(unreservedBandwidth);
linkSubTypeBody.addAll(Bytes.asList(IsisUtil.convertToFourBytes(unresBandwidth)));
}
return Bytes.toArray(linkSubTypeBody);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("unReservedBandwidth", unReservedBandwidth)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.
*/
/**
* Implementation of the ISIS protocol.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
\ No newline at end of file
......@@ -15,6 +15,6 @@
*/
/**
* Implementation of the ISIS protocol.
* Implementation of the ISIS protocol IO.
*/
package org.onosproject.isis.io;
\ No newline at end of file
......
/*
* Copyright 2016-present 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.isis.io.util;
import java.util.Arrays;
/**
* Calculates checksum for ISIS LSP packets.
*/
public class ChecksumCalculator {
/**
* Verifies the checksum is valid in given LSP packet bytes.
*
* @param lspPacket lsp as byte array
* @param lspChecksumPos1 position of checksum bit in packet
* @param lspChecksumPos2 position of checksum bit in packet
* @return true if valid else false
*/
public boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2) {
byte[] checksum = calculateLspChecksum(lspPacket, lspChecksumPos1, lspChecksumPos2);
if (lspPacket[lspChecksumPos1] == checksum[0] && lspPacket[lspChecksumPos2] == checksum[1]) {
return true;
}
return false;
}
/**
* Calculates the LSP checksum.
*
* @param lspBytes as byte array
* @param lspChecksumPos1 position of checksum bit in packet
* @param lspChecksumPos2 position of checksum bit in packet
* @return checksum bytes
*/
public byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) {
byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length);
int[] checksumOut = {0, 0};
tempLsaByte[lspChecksumPos1] = 0;
tempLsaByte[lspChecksumPos2] = 0;
byte[] byteCheckSum = {0, 0};
if (lspBytes != null) {
for (int i = 12; i < tempLsaByte.length; i++) {
checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF);
checksumOut[1] = checksumOut[1] + checksumOut[0];
}
checksumOut[0] = checksumOut[0] % 255;
checksumOut[1] = checksumOut[1] % 255;
}
int byte1 = (int) ((tempLsaByte.length - lspChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255;
if (byte1 <= 0) {
byte1 += 255;
}
int byte2 = 510 - checksumOut[0] - byte1;
if (byte2 > 255) {
byte2 -= 255;
}
byteCheckSum[0] = (byte) byte1;
byteCheckSum[1] = (byte) byte2;
return byteCheckSum;
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.isis.io.util;
/**
* Representation of ISIS constants.
*/
public final class IsisConstants {
public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC
public static final int MINIMUM_FRAME_LEN = 1521;
public static final int METADATA_LEN = 7;
public static final String SHOST = "127.0.0.1";
public static final int SPORT = 3000;
public static final byte L2 = 1;
public static final int IRPDISCRIMINATOR = 131;
public static final int ISISVERSION = 1;
public static final int RESERVED = 0;
public static final int MAXAREAADDRESS = 0;
public static final int IDLENGTH = 0;
public static final int PROTOCOLSUPPORTED = 204;
public static final int LOCALCIRCUITIDFORP2P = 130;
public static final int P2PHELLOHEADERLENGTH = 20;
public static final int HELLOHEADERLENGTH = 27;
public static final int CSNPDUHEADERLENGTH = 33;
public static final int PSNPDUHEADERLENGTH = 17;
public static final int PDULENGTHPOSITION = 17;
public static final int COMMONHEADERLENGTH = 8;
public static final int LSPMAXAGE = 1200;
public static final int LSPREFRESH = 900;
public static final int MAXSEQUENCENUMBER = Integer.MAX_VALUE;
public static final int STARTLSSEQUENCENUM = 1;
public static final int LENGTHPOSITION = 8;
public static final int RESERVEDPOSITION = 6;
public static final int CHECKSUMPOSITION = 24;
public static final String REFRESHLSP = "refreshLsp";
public static final String MAXAGELSP = "maxAgeLsp";
/**
* Non parameterized constructor.
*/
private IsisConstants() {
}
}
......@@ -15,6 +15,6 @@
*/
/**
* Implementation of the ISIS protocol.
* Implementation of the ISIS protocol util.
*/
package org.onosproject.isis.io.util;
\ No newline at end of file
......