Dhruv Dhody
Committed by Gerrit Code Review

ONOS-4083, ONOS-4084, ONOS-4096, ONOS-4097:ISIS PDU Data Structures

Change-Id: I22d30e8f7ba7d414e75254fdec6d0865bf471ff9
Showing 43 changed files with 2205 additions and 243 deletions
......@@ -16,6 +16,7 @@
package org.onosproject.isis.controller;
import java.util.List;
import java.util.Map;
/**
* Representation of an ISIS link state database.
......@@ -93,4 +94,18 @@ public interface IsisLsdb {
* @param lsp LSP instance
*/
void deleteLsp(IsisMessage lsp);
}
/**
* Gets the neighbor database information.
*
* @return neighbor database information
*/
Map<String, LspWrapper> getL1Db();
/**
* Gets the neighbor database information.
*
* @return neighbor database information
*/
Map<String, LspWrapper> getL2Db();
}
\ No newline at end of file
......
......@@ -84,4 +84,18 @@ public interface IsisNeighbor {
* @param localExtendedCircuitId neighbor extended circuit ID
*/
void setLocalExtendedCircuitId(int localExtendedCircuitId);
/**
* Returns Holding time of neighbor.
*
* @return Holding time of neighbor
*/
int holdingTime();
/**
* Sets Holding time of neighbor.
*
* @param holdingTime Holding time of neighbor
*/
void setHoldingTime(int holdingTime);
}
......
/*
* 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.exceptions;
/**
* Defines all error codes and error sub codes.
*/
public final class IsisErrorType {
//Represents an invalid ISIS message header
public static final byte MESSAGE_HEADER_ERROR = 1;
//Represents an invalid ISIS message body
public static final byte ISIS_MESSAGE_ERROR = 2;
//Message Header error sub codes
//Represents an invalid ISIS message length
public static final byte BAD_MESSAGE_LENGTH = 3;
//Represents an invalid ISIS message
public static final byte BAD_MESSAGE = 4;
/**
* Creates an instance of ISIS error type.
*/
private IsisErrorType() {
}
}
\ 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.exceptions;
import com.google.common.base.MoreObjects;
/**
* Representation of a custom exception for ISIS.
*/
public class IsisParseException extends Exception {
private static final long serialVersionUID = 1L;
private byte errorCode;
private byte errorSubCode;
/**
* Creates a new ISIS exception.
*/
public IsisParseException() {
super();
}
/**
* Creates a new ISIS exception based on the given arguments.
*
* @param message the detail of exception in string
* @param cause underlying cause of the error
*/
public IsisParseException(final String message, final Throwable cause) {
super(message, cause);
}
/**
* Creates a new ISIS exception for the given message.
*
* @param message the detail of exception in string
*/
public IsisParseException(final String message) {
super(message);
}
/**
* Creates a new ISIS exception from throwable instance.
*
* @param cause underlying cause of the error
*/
public IsisParseException(final Throwable cause) {
super(cause);
}
/**
* Creates a new ISIS exception from error code and error sub code.
*
* @param errorCode error code of ISIS message
* @param errorSubCode error sub code of ISIS message
*/
public IsisParseException(final byte errorCode, final byte errorSubCode) {
super();
this.errorCode = errorCode;
this.errorSubCode = errorSubCode;
}
/**
* Returns error code for this exception.
*
* @return error code for this exception
*/
public byte errorCode() {
return this.errorCode;
}
/**
* Returns error sub code for this exception.
*
* @return error sub code for this exception
*/
public byte errorSubCode() {
return this.errorSubCode;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("errorCode", errorCode)
.add("errorSubCode", errorSubCode)
.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 exceptions.
*/
package org.onosproject.isis.exceptions;
/*
* 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;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.MacAddress;
import org.onosproject.isis.controller.IsisMessage;
import org.onosproject.isis.controller.IsisPduType;
/**
* Representation of ISIS message header.
*/
public class IsisHeader implements IsisMessage {
private MacAddress sourceMac;
private int interfaceIndex;
private MacAddress interfaceMac;
private int isisPduType;
private byte irpDiscriminator;
private byte pduHeaderLength;
private byte version2;
private byte idLength;
private byte version;
private byte reserved;
private byte maximumAreaAddresses;
/**
* Returns the interface index on which the message received.
*
* @return interface index on which the message received
*/
public int interfaceIndex() {
return interfaceIndex;
}
/**
* Sets the interface index on which the message received.
*
* @param interfaceIndex interface index on which the message received
*/
public void setInterfaceIndex(int interfaceIndex) {
this.interfaceIndex = interfaceIndex;
}
/**
* Returns the interface mac address on which the message received.
*
* @return interface mac address on which the message received
*/
public MacAddress interfaceMac() {
return interfaceMac;
}
/**
* Returns the mac address of the message sender.
*
* @return mac address of the message sender
*/
public MacAddress sourceMac() {
return sourceMac;
}
/**
* Sets the mac address of the message sender.
*
* @param sourceMac mac address of the message sender
*/
public void setSourceMac(MacAddress sourceMac) {
this.sourceMac = sourceMac;
}
/**
* Sets the interface mac address on which the message received.
*
* @param interfaceMac mac address on which the message received
*/
public void setInterfaceMac(MacAddress interfaceMac) {
this.interfaceMac = interfaceMac;
}
/**
* Returns the version of TLV header.
*
* @return version version of TLV header
*/
public byte version2() {
return version2;
}
/**
* Sets the version of TLV header.
*
* @param version2 version of TLV header
*/
public void setVersion2(byte version2) {
this.version2 = version2;
}
/**
* Returns maximum area address.
*
* @return maximum area address
*/
public byte maximumAreaAddresses() {
return maximumAreaAddresses;
}
/**
* Sets maximum area address.
*
* @param maximumAreaAddresses maximum area address
*/
public void setMaximumAreaAddresses(byte maximumAreaAddresses) {
this.maximumAreaAddresses = maximumAreaAddresses;
}
/**
* Returns reserved field value on which data received.
*
* @return reserved
*/
public byte reserved() {
return reserved;
}
/**
* Sets reserved.
*
* @param reserved reserved
*/
public void setReserved(byte reserved) {
this.reserved = reserved;
}
/**
* Returns version.
*
* @return version
*/
public byte version() {
return version;
}
/**
* Returns ID length.
*
* @return ID length
*/
public byte idLength() {
return idLength;
}
/**
* Sets ID length.
*
* @param idLength ID length
*/
public void setIdLength(byte idLength) {
this.idLength = idLength;
}
/**
* Returns the PDU type.
*
* @return PDU type
*/
public int pduType() {
return this.isisPduType;
}
/**
* Sets PDU type.
*
* @param isisPduType PDU type
*/
public void setIsisPduType(int isisPduType) {
this.isisPduType = isisPduType;
}
/**
* Sets protocol ID.
*
* @param version protocol ID
*/
public void setVersion(byte version) {
this.version = version;
}
/**
* Returns length indicator.
*
* @return length indicator
*/
public byte pduHeaderLength() {
return pduHeaderLength;
}
/**
* Sets length indicator.
*
* @param pduHeaderLength length indicator
*/
public void setPduHeaderLength(byte pduHeaderLength) {
this.pduHeaderLength = pduHeaderLength;
}
/**
* Returns IRP discriminator.
*
* @return IRP discriminator
*/
public byte irpDiscriminator() {
return irpDiscriminator;
}
/**
* Sets IRP discriminator.
*
* @param irpDiscriminator IRP discriminator
*/
public void setIrpDiscriminator(byte irpDiscriminator) {
this.irpDiscriminator = irpDiscriminator;
}
@Override
public IsisPduType isisPduType() {
return IsisPduType.get(this.isisPduType);
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
//implemented in the sub classes
}
@Override
public byte[] asBytes() {
return null;
}
/**
* Populates ISIS header.
*
* @param isisHeader ISIS header
*/
public void populateHeader(IsisHeader isisHeader) {
this.setIrpDiscriminator(isisHeader.irpDiscriminator());
this.setPduHeaderLength(isisHeader.pduHeaderLength());
this.setVersion(isisHeader.version());
this.setIdLength(isisHeader.idLength());
this.setIsisPduType(isisHeader.pduType());
this.setVersion2(isisHeader.version2());
this.setReserved(isisHeader.reserved());
this.setMaximumAreaAddresses(isisHeader.maximumAreaAddresses());
}
}
\ 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;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.controller.IsisMessage;
import org.onosproject.isis.exceptions.IsisErrorType;
import org.onosproject.isis.exceptions.IsisParseException;
import org.onosproject.isis.io.isispacket.pdu.Csnp;
import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
import org.onosproject.isis.io.isispacket.pdu.Psnp;
import org.onosproject.isis.io.util.IsisConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Represents ISIS message reader.
*/
public class IsisMessageReader {
protected static final Logger log = LoggerFactory.getLogger(IsisMessageReader.class);
/**
* Reads from ISIS packet from buffer.
*
* @param channelBuffer buffer
* @return ISIS message
* @throws Exception exception
*/
public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception {
int dataLength = channelBuffer.readableBytes();
log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength);
if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) {
log.debug("Packet should have minimum length...");
throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH);
}
IsisHeader isisHeader = getIsisHeader(channelBuffer);
int totalLength = 0;
IsisMessage isisMessage = null;
switch (isisHeader.isisPduType()) {
case L1HELLOPDU:
case L2HELLOPDU:
isisMessage = new L1L2HelloPdu(isisHeader);
totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
break;
case P2PHELLOPDU:
isisMessage = new P2PHelloPdu(isisHeader);
totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
break;
case L1LSPDU:
case L2LSPDU:
isisMessage = new LsPdu(isisHeader);
totalLength = channelBuffer.getShort(8);
break;
case L1CSNP:
case L2CSNP:
isisMessage = new Csnp(isisHeader);
totalLength = channelBuffer.getShort(8);
break;
case L1PSNP:
case L2PSNP:
isisMessage = new Psnp(isisHeader);
totalLength = channelBuffer.getShort(8);
break;
default:
log.debug("Message Reader[Decoder] - Unknown PDU type..!!!");
break;
}
if (isisMessage != null) {
try {
int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH;
isisMessage.readFrom(channelBuffer.readBytes(bodyLength));
} catch (Exception e) {
throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR,
IsisErrorType.BAD_MESSAGE);
}
}
return isisMessage;
}
/**
* Gets ISIS header.
*
* @param channelBuffer ISIS header
* @return ISIS header
* @throws Exception
*/
private IsisHeader getIsisHeader(ChannelBuffer channelBuffer) throws Exception {
IsisHeader isisHeader = new IsisHeader();
isisHeader.setIrpDiscriminator(channelBuffer.readByte());
isisHeader.setPduHeaderLength(channelBuffer.readByte());
isisHeader.setVersion(channelBuffer.readByte());
isisHeader.setIdLength(channelBuffer.readByte());
isisHeader.setIsisPduType(channelBuffer.readByte());
isisHeader.setVersion2(channelBuffer.readByte());
isisHeader.setReserved(channelBuffer.readByte());
isisHeader.setMaximumAreaAddresses(channelBuffer.readByte());
return isisHeader;
}
}
\ 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.pdu;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Representation of attached to other areas.
*/
public enum AttachedToOtherAreas {
DEFAULTMETRIC(1),
DELAYMETRIC(2),
EXPENSEMETRIC(4),
ERRORMETRIC(8),
NONE(0);
// Reverse lookup table
private static final Map<Integer, AttachedToOtherAreas> LOOKUP = new HashMap<>();
// Populate the lookup table on loading time
static {
for (AttachedToOtherAreas attachedToOtherAreas :
EnumSet.allOf(AttachedToOtherAreas.class)) {
LOOKUP.put(attachedToOtherAreas.value(), attachedToOtherAreas);
}
}
private int value;
/**
* Returns the attached to other areas value.
*
* @param value attached to other areas value
*/
AttachedToOtherAreas(int value) {
this.value = value;
}
/**
* Returns the value for attached to other areas from pdu type value.
*
* @param pduTypeValue to get attached areas value
* @return attachedToOtherAreas value of the enum
*/
public static AttachedToOtherAreas get(int pduTypeValue) {
return LOOKUP.get(pduTypeValue);
}
/**
* Returns the value representing PDU type.
*
* @return value represents PDU type
*/
public int value() {
return value;
}
}
\ 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.pdu;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of complete sequence number PDU.
*/
public class Csnp extends IsisHeader {
/*
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Intra-domain Routing Protocol Discriminator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length Indicator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version/Protocol ID Extension |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R | R | R | PDU Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum area address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PDU Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start LSP ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| End LSP ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Variable Lengths Fields |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
CSNP Message Format
REFERENCE : ISO/IEC 10589
*/
private int pduLength;
private String sourceId;
private String startLspId;
private String endLspId;
private List<IsisTlv> variableLengths = new ArrayList<>();
/**
* Creates the instance for this class.
*
* @param isisHeader ISIS header
*/
public Csnp(IsisHeader isisHeader) {
populateHeader(isisHeader);
}
/**
* Returns the list of all tlvs.
*
* @return variableLengths list of tlvs
*/
public List<IsisTlv> getAllTlv() {
return variableLengths;
}
/**
* Returns the source ID of csnp.
*
* @return sourceId source ID
*/
public String sourceId() {
return sourceId;
}
/**
* Sets the source ID for csnp.
*
* @param sourceId source ID
*/
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
/**
* Returns the initial link state packet ID of csnp.
*
* @return startLspId start link state packet ID
*/
public String startLspId() {
return startLspId;
}
/**
* Sets the initial link state packet ID for csnp.
*
* @param startLspId start link state packet ID
*/
public void setStartLspId(String startLspId) {
this.startLspId = startLspId;
}
/**
* Returns the end link state packet ID of csnp.
*
* @return endLspId end link state packet ID of csnp.
*/
public String endLspId() {
return endLspId;
}
/**
* Sets the end link state packet ID for csnp.
*
* @param endLspId end link state packet ID of csnp.
*/
public void setEndLspId(String endLspId) {
this.endLspId = endLspId;
}
/**
* Returns the packet data unit length of link state packet.
* Entire length of this PDU, in octets
*
* @return pduLength packet date unit length
*/
public int pduLength() {
return pduLength;
}
/**
* Sets the packet data unit length for link state packet.
* Entire Length of this PDU, in octets
*
* @param pduLength packet data length
*/
public void setPduLength(int pduLength) {
this.pduLength = pduLength;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setPduLength(channelBuffer.readUnsignedShort());
//source id + 1 value
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setSourceId(IsisUtil.systemIdPlus(tempByteArray));
//start lsp id + 2 value
tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
this.setStartLspId(IsisUtil.systemIdPlus(tempByteArray));
//end lsp id + 2 value
tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
this.setEndLspId(IsisUtil.systemIdPlus(tempByteArray));
//tlv here
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
TlvType tlvValue = TlvType.get(tlvHeader.tlvType());
if (tlvValue != null) {
IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
this.variableLengths.add(tlv);
} else {
channelBuffer.readBytes(tlvHeader.tlvLength());
}
}
}
@Override
public byte[] asBytes() {
byte[] csnpMessage = null;
byte[] isisPduHeader = isisPduHeader();
byte[] csnpBody = completeSequenceNumberPduBody();
csnpMessage = Bytes.concat(isisPduHeader, csnpBody);
return csnpMessage;
}
/**
* Builds ISIS PDU header for complete sequence numbers PDU.
*
* @return isisPduHeader ISIS PDU header
*/
public byte[] isisPduHeader() {
List<Byte> headerList = new ArrayList<>();
headerList.add(this.irpDiscriminator());
headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
headerList.add(this.version());
headerList.add(this.idLength());
headerList.add((byte) this.pduType());
headerList.add(this.version2());
headerList.add(this.reserved());
headerList.add(this.maximumAreaAddresses());
return Bytes.toArray(headerList);
}
/**
* Builds complete sequence numbers PDU body.
*
* @return bodyList complete sequence numbers PDU body
*/
public byte[] completeSequenceNumberPduBody() {
List<Byte> bodyList = new ArrayList<>();
bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.startLspId()));
bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.endLspId()));
for (IsisTlv isisTlv : variableLengths) {
bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
}
return Bytes.toArray(bodyList);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("pduLength", pduLength)
.add("sourceId", sourceId)
.add("startLspId", startLspId)
.add("endLspId", endLspId)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Csnp that = (Csnp) o;
return Objects.equal(pduLength, that.pduLength) &&
Objects.equal(sourceId, that.sourceId) &&
Objects.equal(startLspId, that.startLspId) &&
Objects.equal(endLspId, that.endLspId);
}
@Override
public int hashCode() {
return Objects.hashCode(pduLength, sourceId, startLspId, endLspId);
}
}
\ 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.pdu;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.isis.controller.IsisInterfaceState;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv;
import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv;
import org.onosproject.isis.io.isispacket.tlv.IsisNeighborTlv;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of ISIS hello PDU.
*/
public abstract class HelloPdu extends IsisHeader {
protected List<IsisTlv> variableLengths = new ArrayList<>();
private byte circuitType;
private String sourceId;
private int holdingTime;
private int pduLength;
public void addTlv(IsisTlv isisTlv) {
variableLengths.add(isisTlv);
}
/**
* Returns the variable lengths.
*
* @return variable lengths
*/
public List<IsisTlv> tlvs() {
return variableLengths;
}
/**
* Returns the list of area addresses.
*
* @return areaAddresses area addresses
*/
public List<String> areaAddress() {
List<String> areaAddresses = null;
for (IsisTlv tlv : tlvs()) {
if (tlv instanceof AreaAddressTlv) {
areaAddresses = ((AreaAddressTlv) tlv).areaAddress();
}
}
return areaAddresses;
}
/**
* Returns the list of interface IP addresses.
*
* @return interfaceIpAddresses list of interface IP addresses
*/
public List<Ip4Address> interfaceIpAddresses() {
List<Ip4Address> interfaceIpAddresses = null;
for (IsisTlv tlv : tlvs()) {
if (tlv instanceof IpInterfaceAddressTlv) {
interfaceIpAddresses = ((IpInterfaceAddressTlv) tlv).interfaceAddress();
}
}
return interfaceIpAddresses;
}
/**
* Returns the list of neighbor list.
*
* @return macAddresses list of neighbor MAC address
*/
public List<MacAddress> neighborList() {
List<MacAddress> macAddresses = null;
for (IsisTlv tlv : tlvs()) {
if (tlv instanceof IsisNeighborTlv) {
macAddresses = ((IsisNeighborTlv) tlv).neighbor();
}
}
return macAddresses;
}
/**
* Returns the adjacency state.
*
* @return interfaceState adjacency state
*/
public IsisInterfaceState adjacencyState() {
IsisInterfaceState interfaceState = null;
for (IsisTlv tlv : tlvs()) {
if (tlv instanceof AdjacencyStateTlv) {
interfaceState = IsisInterfaceState.get(((AdjacencyStateTlv) tlv).adjacencyType());
break;
}
}
return interfaceState;
}
/**
* Returns the source ID.
*
* @return sourceId source ID
*/
public String sourceId() {
return sourceId;
}
/**
* Sets source ID.
*
* @param sourceId source ID
*/
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
/**
* Returns the PDU length.
*
* @return pduLength PDU length
*/
public int pduLength() {
return pduLength;
}
/**
* Sets the PDU length.
*
* @param pduLength PDU lenght
*/
public void setPduLength(int pduLength) {
this.pduLength = pduLength;
}
/**
* Returns the holding time.
*
* @return holdingTime holding time
*/
public int holdingTime() {
return holdingTime;
}
/**
* Sets the holding time.
*
* @param holdingTime holding time
*/
public void setHoldingTime(int holdingTime) {
this.holdingTime = holdingTime;
}
/**
* Returns the circuit type.
*
* @return circuitType circuit type
*/
public byte circuitType() {
return circuitType;
}
/**
* Sets the circuit type.
*
* @param circuitType circuit type
*/
public void setCircuitType(byte circuitType) {
this.circuitType = circuitType;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("circuitType", circuitType)
.add("sourceId", sourceId)
.add("holdingTime", holdingTime)
.add("pduLength", pduLength)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HelloPdu that = (HelloPdu) o;
return Objects.equal(circuitType, that.circuitType) &&
Objects.equal(sourceId, that.sourceId) &&
Objects.equal(holdingTime, that.holdingTime) &&
Objects.equal(pduLength, that.pduLength);
}
@Override
public int hashCode() {
return Objects.hashCode(circuitType, sourceId, holdingTime, pduLength);
}
}
\ 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.pdu;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of L1L2 hello PDU.
*/
public class L1L2HelloPdu extends HelloPdu {
/*
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Intra-domain Routing Protocol Discriminator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length Indicator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version/Protocol ID Extension |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R | R | R | PDU Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum area address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Circuit Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Holding Time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PDU Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PDU Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R | Priority |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LAN ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Variable Lengths Fields |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Hello Message Format
REFERENCE : ISO/IEC 10589
*/
private byte priority;
private String lanId;
/**
* Parametrized constructor.
*
* @param isisHeader ISIs header
*/
public L1L2HelloPdu(IsisHeader isisHeader) {
populateHeader(isisHeader);
}
/**
* Returns the LAN ID.
*
* @return LAN ID
*/
public String lanId() {
return lanId;
}
/**
* Sets the LAN ID.
*
* @param lanId LAN ID
*/
public void setLanId(String lanId) {
this.lanId = lanId;
}
/**
* Returns the priority.
*
* @return priority
*/
public byte priority() {
return priority;
}
/**
* Sets priority.
*
* @param priority priority
*/
public void setPriority(byte priority) {
this.priority = priority;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setCircuitType(channelBuffer.readByte());
//sorce id
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setSourceId(IsisUtil.systemId(tempByteArray));
this.setHoldingTime(channelBuffer.readUnsignedShort());
this.setPduLength(channelBuffer.readUnsignedShort());
this.setPriority(channelBuffer.readByte());
//landid id + 1 value
tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setLanId(IsisUtil.systemIdPlus(tempByteArray));
//tlv here
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
TlvType tlvType = TlvType.get(tlvHeader.tlvType());
if (tlvType != null) {
IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
this.variableLengths.add(tlv);
} else {
channelBuffer.readBytes(tlvHeader.tlvLength());
}
}
}
@Override
public byte[] asBytes() {
byte[] helloMessage = null;
byte[] helloHeader = l1l2IsisPduHeader();
byte[] helloBody = l1l2HelloPduBody();
helloMessage = Bytes.concat(helloHeader, helloBody);
return helloMessage;
}
/**
* Parse the ISIS L1L2 PDU header.
*
* @return ISIS L1L2 PDU header
*/
public byte[] l1l2IsisPduHeader() {
List<Byte> headerLst = new ArrayList<>();
headerLst.add(this.irpDiscriminator());
headerLst.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
headerLst.add(this.version());
headerLst.add(this.idLength());
headerLst.add((byte) this.pduType());
headerLst.add(this.version2());
headerLst.add(this.reserved());
headerLst.add(this.maximumAreaAddresses());
return Bytes.toArray(headerLst);
}
/**
* Parse the ISIS L1L2 PDU body.
*
* @return ISIS L1L2 PDU body
*/
public byte[] l1l2HelloPduBody() {
List<Byte> bodyLst = new ArrayList<>();
bodyLst.add(this.circuitType());
bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime())));
bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
bodyLst.add(this.priority);
bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.lanId()));
for (IsisTlv isisTlv : variableLengths) {
bodyLst.addAll(TlvsToBytes.tlvToBytes(isisTlv));
}
return Bytes.toArray(bodyLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("priority", priority)
.add("lanId", lanId)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
L1L2HelloPdu that = (L1L2HelloPdu) o;
return Objects.equal(priority, that.priority) &&
Objects.equal(lanId, that.lanId);
}
@Override
public int hashCode() {
return Objects.hashCode(priority, lanId);
}
}
\ 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.pdu;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of P2P hello.
*/
public class P2PHelloPdu extends HelloPdu {
/*
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Intra-domain Routing Protocol Discriminator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length Indicator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version/Protocol ID Extension |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R | R | R | PDU Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum area address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Circuit Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Holding Time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PDU Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Local Circuit Id |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Variable Lengths Fields |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
P2P Hello Message Format
REFERENCE : ISO/IEC 10589
*/
private byte localCircuitId;
/**
* Sets the ISIS header.
*
* @param isisHeader isisHeader
*/
public P2PHelloPdu(IsisHeader isisHeader) {
populateHeader(isisHeader);
}
/**
* Returns the local circuit ID.
*
* @return Local circuit ID
*/
public byte localCircuitId() {
return localCircuitId;
}
/**
* Sets the local circuit ID.
*
* @param localCircuitId Local circuit ID
*/
public void setLocalCircuitId(byte localCircuitId) {
this.localCircuitId = localCircuitId;
}
/**
* Sets the variable lengths.
*
* @param variableLengths variable lengths.
*/
public void setVariableLengths(List<IsisTlv> variableLengths) {
this.variableLengths = variableLengths;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setCircuitType(channelBuffer.readByte());
//source id
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setSourceId(IsisUtil.systemId(tempByteArray));
this.setHoldingTime(channelBuffer.readUnsignedShort());
this.setPduLength(channelBuffer.readUnsignedShort());
this.setLocalCircuitId((byte) channelBuffer.readUnsignedByte());
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
TlvType tlvType = TlvType.get(tlvHeader.tlvType());
if (tlvType != null) {
IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
this.variableLengths.add(tlv);
} else {
channelBuffer.readBytes(tlvHeader.tlvLength());
}
}
}
@Override
public byte[] asBytes() {
byte[] helloMessage = null;
byte[] helloHeader = p2PHeader();
byte[] helloBody = p2P2HelloPduBody();
helloMessage = Bytes.concat(helloHeader, helloBody);
return helloMessage;
}
/**
* Builds the point to point header.
*
* @return headerList point to point header
*/
public byte[] p2PHeader() {
List<Byte> headerList = new ArrayList<>();
headerList.add(this.irpDiscriminator());
headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
headerList.add(this.version());
headerList.add(this.idLength());
headerList.add((byte) this.pduType());
headerList.add(this.version2());
headerList.add(this.reserved());
headerList.add(this.maximumAreaAddresses());
return Bytes.toArray(headerList);
}
/**
* Builds the point to point hello PDU body.
*
* @return bodyList point to point hello PDU body
*/
public byte[] p2P2HelloPduBody() {
List<Byte> bodyList = new ArrayList<>();
bodyList.add(this.circuitType());
bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime())));
bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
bodyList.add((byte) this.localCircuitId());
for (IsisTlv isisTlv : variableLengths) {
bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
}
return Bytes.toArray(bodyList);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("localCircuitId", localCircuitId)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
P2PHelloPdu that = (P2PHelloPdu) o;
return Objects.equal(localCircuitId, that.localCircuitId);
}
@Override
public int hashCode() {
return Objects.hashCode(localCircuitId);
}
}
\ 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.pdu;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvFinder;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import org.onosproject.isis.io.isispacket.tlv.TlvsToBytes;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of partial sequence number PDU.
*/
public class Psnp extends IsisHeader {
/*
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Intradomain Routing Protocol Discriminator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length Indicator |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version/Protocol ID Extension |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R | R | R | PDU Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum area address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PDU Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start LSP ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| End LSP ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Variable Lengths Fields |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Hello Message Format
REFERENCE : ISO/IEC 10589
*/
private int pduLength;
private String sourceId;
private List<IsisTlv> variableLengths = new ArrayList<>();
/**
* Creates the instance for this class.
*
* @param isisHeader ISIS header
*/
public Psnp(IsisHeader isisHeader) {
populateHeader(isisHeader);
}
public void addTlv(IsisTlv isisTlv) {
variableLengths.add(isisTlv);
}
/**
* Returns the source ID of csnp.
*
* @return sourceId source ID
*/
public String sourceId() {
return sourceId;
}
/**
* Sets the source ID for csnp.
*
* @param sourceId source ID
*/
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
/**
* Returns the packet data unit length of link state packet.
* Entire length of this PDU, in octets
*
* @return pduLength packte date unit length
*/
public int pduLength() {
return pduLength;
}
/**
* Sets the packet data unit length for link state packet.
* Entire Length of this PDU, in octets
*
* @param pduLength packte data length
*/
public void setPduLength(int pduLength) {
this.pduLength = pduLength;
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setPduLength(channelBuffer.readUnsignedShort());
//source id + 2 value
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setSourceId(IsisUtil.systemIdPlus(tempByteArray));
//tlv here
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readUnsignedByte());
tlvHeader.setTlvLength(channelBuffer.readUnsignedByte());
TlvType tlvValue = TlvType.get(tlvHeader.tlvType());
if (tlvValue != null) {
IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
this.variableLengths.add(tlv);
} else {
channelBuffer.readBytes(tlvHeader.tlvLength());
}
}
}
@Override
public byte[] asBytes() {
byte[] psnpMessage = null;
byte[] isisPduHeader = isisPduHeader();
byte[] psnpBody = partialSequenceNumberPduBody();
psnpMessage = Bytes.concat(isisPduHeader, psnpBody);
return psnpMessage;
}
/**
* Builds the ISIS PDU header.
*
* @return headerList ISIS PDU header
*/
public byte[] isisPduHeader() {
List<Byte> headerList = new ArrayList<>();
headerList.add(this.irpDiscriminator());
headerList.add((byte) IsisUtil.getPduHeaderLength(this.pduType()));
headerList.add(this.version());
headerList.add(this.idLength());
headerList.add((byte) this.pduType());
headerList.add(this.version2());
headerList.add(this.reserved());
headerList.add(this.maximumAreaAddresses());
return Bytes.toArray(headerList);
}
/**
* Builds the partial sequence number PDU body.
*
* @return bodyList partial sequence number PDU body
*/
public byte[] partialSequenceNumberPduBody() {
List<Byte> bodyList = new ArrayList<>();
bodyList.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
bodyList.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
for (IsisTlv isisTlv : variableLengths) {
bodyList.addAll(TlvsToBytes.tlvToBytes(isisTlv));
}
return Bytes.toArray(bodyList);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("pduLength", pduLength)
.add("sourceId", sourceId)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Psnp that = (Psnp) o;
return Objects.equal(pduLength, that.pduLength);
}
@Override
public int hashCode() {
return Objects.hashCode(sourceId, pduLength);
}
}
\ 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.pdu;
\ No newline at end of file
......@@ -36,7 +36,7 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of adjacency state TLV..
*
* @param tlvHeader tlvHeader
* @param tlvHeader TLV header
*/
public AdjacencyStateTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......@@ -118,8 +118,8 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv {
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setAdjacencyType(channelBuffer.readByte());
this.setLocalCircuitId(channelBuffer.readInt());
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));
......@@ -146,8 +146,10 @@ public class AdjacencyStateTlv extends TlvHeader implements IsisTlv {
List<Byte> bytes = new ArrayList<>();
bytes.add(this.adjacencyType);
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.localCircuitId)));
if (this.neighborSystemId != null) {
bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborSystemId));
bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.neighborLocalCircuitId)));
}
return Bytes.toArray(bytes);
}
......
......@@ -33,7 +33,7 @@ public class AreaAddressTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of area address TLV.
*
* @param tlvHeader tlvHeader
* @param tlvHeader TLV header
*/
public AreaAddressTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -28,7 +28,7 @@ public class HostNameTlv extends TlvHeader {
/**
* Creates an instance of host name TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public HostNameTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -29,7 +29,7 @@ public class IdrpInformationTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of IDRP information TLV.
*
* @param tlvHeader tlvHeader
* @param tlvHeader TLV header
*/
public IdrpInformationTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -21,6 +21,7 @@ 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.SubTlvType;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.util.IsisUtil;
......@@ -32,15 +33,18 @@ import java.util.List;
*/
public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
private String sysIdAndPseudoNumber;
private int defaultMetric;
private boolean down;
private boolean subTlvPresence;
private int prefixLength;
private int metric;
private byte subTlvLength;
private String prefix;
private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
/**
* Creates an instance of IP external reachability TLV.
*
* @param tlvHeader tlvHeader
* @param tlvHeader TLV header
*/
public IpExtendedReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......@@ -48,21 +52,75 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
}
/**
* Returns the system ID and pseudo number of IP external reachability TLV.
* Returns the prefix of IP external reachability TLV.
*
* @return sysIdAndPseudoNumber system ID and pseudo number
* @return prefix
*/
public String sysIdAndPseudoNumber() {
return sysIdAndPseudoNumber;
public String prefix() {
return prefix;
}
/**
* Sets the system ID and pseudo number for IP external reachability TLV.
* Sets the prefix of IP external reachability TLV.
*
* @param sysIdAndPseudoNumber system ID and pseudo number
* @param prefix prefix
*/
public void setSysIdAndPseudoNumber(String sysIdAndPseudoNumber) {
this.sysIdAndPseudoNumber = sysIdAndPseudoNumber;
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
* Returns if down true else false of IP external reachability TLV.
*
* @return if down true else false
*/
public boolean isDown() {
return down;
}
/**
* Sets if down true else false of IP external reachability TLV.
*
* @param upOrDown if down true else false
*/
public void setDown(boolean upOrDown) {
this.down = upOrDown;
}
/**
* Returns true if sub TLV present else false of IP external reachability TLV.
*
* @return true if present else false
*/
public boolean isSubTlvPresence() {
return subTlvPresence;
}
/**
* Sets true if sub TLV present else false of IP external reachability TLV.
*
* @param subTlvPresence true if present else false
*/
public void setSubTlvPresence(boolean subTlvPresence) {
this.subTlvPresence = subTlvPresence;
}
/**
* Sets the prefix length of IP external reachability TLV.
*
* @return prefix length
*/
public int prefixLength() {
return prefixLength;
}
/**
* Returns the prefix length of IP external reachability TLV.
*
* @param prefixLength the prefix length of IP external reachability TLV
*/
public void setPrefixLength(int prefixLength) {
this.prefixLength = prefixLength;
}
/**
......@@ -93,39 +151,70 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
}
/**
* Returns default metric of IP external reachability TLV.
* Returns metric of IP external reachability TLV.
*
* @return default metric
* @return metric
*/
public int defaultMetric() {
return defaultMetric;
public int metric() {
return metric;
}
/**
* Sets default metric for IP external reachability TLV.
*
* @param defaultMetric default metric
* @param metric default metric
*/
public void setDefaultMetric(int defaultMetric) {
this.defaultMetric = defaultMetric;
public void setMetric(int metric) {
this.metric = metric;
}
@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())));
this.setMetric(channelBuffer.readInt());
int controlInfo = channelBuffer.readByte();
byte[] tempByteArray = null;
String string = IsisUtil.toEightBitBinary(Integer.toBinaryString(controlInfo));
if (string.charAt(0) == '0') {
this.setDown(false);
}
if (string.charAt(1) == '1') {
this.setSubTlvPresence(true);
}
this.setPrefixLength(Integer.parseInt(string.substring(2, string.length()), 2));
if (this.prefixLength >= 0 && this.prefixLength <= 8) {
channelBuffer.readByte();
} else if (this.prefixLength >= 8 && this.prefixLength <= 16) {
tempByteArray = new byte[IsisUtil.TWO_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.TWO_BYTES);
this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
} else if (this.prefixLength >= 17 && this.prefixLength <= 24) {
tempByteArray = new byte[IsisUtil.THREE_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.THREE_BYTES);
this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
} else if (this.prefixLength >= 24 && this.prefixLength <= 32) {
tempByteArray = new byte[IsisUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES);
this.setPrefix(IsisUtil.prefixConversion(tempByteArray));
}
if (this.isSubTlvPresence()) {
this.setSubTlvLength(channelBuffer.readByte());
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readByte());
tlvHeader.setTlvLength(channelBuffer.readByte());
SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType());
if (tlvValue != null) {
this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
channelBuffer.readBytes(tlvHeader.tlvLength())));
} else {
channelBuffer.readBytes(tlvHeader.tlvLength());
}
}
}
}
@Override
public byte[] asBytes() {
byte[] bytes = null;
......@@ -145,11 +234,26 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
*/
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));
bodyLst.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.metric())));
String controlInfo = "";
if (this.isDown()) {
controlInfo = controlInfo + "1";
} else {
controlInfo = controlInfo + "0";
}
if (this.isSubTlvPresence()) {
controlInfo = controlInfo + "1";
} else {
controlInfo = controlInfo + "0";
}
String prefixlength = IsisUtil.toEightBitBinary(Integer.toBinaryString(this.prefixLength()));
controlInfo = controlInfo + prefixlength.substring(2, prefixlength.length());
bodyLst.add(Byte.parseByte(controlInfo, 2));
if (this.isSubTlvPresence()) {
bodyLst.add(this.subTlvLength());
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
}
return Bytes.toArray(bodyLst);
}
......@@ -158,9 +262,12 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv {
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("sysIdAndPseudoNumber", sysIdAndPseudoNumber)
.add("defaultMetric", defaultMetric)
.add("down", down)
.add("subTlvPresence", subTlvPresence)
.add("prefixLength", prefixLength)
.add("metric", metric)
.add("subTlvLength", subTlvLength)
.add("prefix", prefix)
.add("trafEnginSubTlv", trafEnginSubTlv)
.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.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
......@@ -34,7 +34,7 @@ public class IpInterfaceAddressTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of IP interface address TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public IpInterfaceAddressTlv(TlvHeader tlvHeader) {
......
......@@ -31,7 +31,7 @@ public class IpInternalReachabilityTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of IP internal reachability TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public IpInternalReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -33,7 +33,7 @@ public class IsReachabilityTlv extends TlvHeader {
/**
* Creates an instance of IS reachability TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public IsReachabilityTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -34,7 +34,7 @@ public class IsisNeighborTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of ISIS neighbor TLV.
*
* @param tlvHeader tlvHeader
* @param tlvHeader TLV header
*/
public IsisNeighborTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -31,7 +31,7 @@ public class LspEntriesTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of LSP entries TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public LspEntriesTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -46,7 +46,7 @@ public class LspEntry {
/**
* Sets LSP sequenceNumber for LSP entry.
*
* @param lspSequenceNumber lspSequenceNumber.
* @param lspSequenceNumber lspSequenceNumber
*/
public void setLspSequenceNumber(int lspSequenceNumber) {
this.lspSequenceNumber = lspSequenceNumber;
......@@ -113,11 +113,11 @@ public class LspEntry {
*/
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);
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_TWO_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_TWO_BYTE);
this.setLspId(IsisUtil.systemIdPlus(tempByteArray));
this.setLspSequenceNumber(channelBuffer.readInt());
this.setLspChecksum(channelBuffer.readUnsignedByte());
this.setLspChecksum(channelBuffer.readUnsignedShort());
}
/**
......
......@@ -226,7 +226,7 @@ public class MetricOfInternalReachability {
/**
* Returns error metric of metric of internal reachability.
*
* @return errorMetric error metic
* @return errorMetric error metric
*/
public byte errorMetric() {
return errorMetric;
......
......@@ -217,7 +217,7 @@ public class MetricsOfReachability {
/**
* Sets delay metric for metric of reachability.
*
* @param delayMetric delay metric.
* @param delayMetric delay metric
*/
public void setDelayMetric(byte delayMetric) {
this.delayMetric = delayMetric;
......@@ -235,7 +235,7 @@ public class MetricsOfReachability {
/**
* Sets Expense metric for metric of reachability.
*
* @param expenseMetric Expense metric.
* @param expenseMetric Expense metric
*/
public void setExpenseMetric(byte expenseMetric) {
this.expenseMetric = expenseMetric;
......@@ -253,7 +253,7 @@ public class MetricsOfReachability {
/**
* Sets Error metric for metric of reachability.
*
* @param errorMetric Error metric.
* @param errorMetric Error metric
*/
public void setErrorMetric(byte errorMetric) {
this.errorMetric = errorMetric;
......
......@@ -31,7 +31,7 @@ public class PaddingTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of padding TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public PaddingTlv(TlvHeader tlvHeader) {
this.setTlvType(tlvHeader.tlvType());
......
......@@ -32,7 +32,7 @@ public class ProtocolSupportedTlv extends TlvHeader implements IsisTlv {
/**
* Creates an instance of protocol supported TLV.
*
* @param tlvHeader tlvHeader.
* @param tlvHeader TLV header
*/
public ProtocolSupportedTlv(TlvHeader tlvHeader) {
......
......@@ -44,6 +44,11 @@ public class TlvFinder extends TlvHeader {
case EXTENDEDISREACHABILITY:
//TODO
break;
case HOSTNAME:
HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader);
hostNameTlv.readFrom(channelBuffer);
isisTlv = hostNameTlv;
break;
case IDRPINFORMATION:
IdrpInformationTlv idrpInformationTlv = new IdrpInformationTlv(tlvHeader);
idrpInformationTlv.readFrom(channelBuffer);
......
......@@ -40,7 +40,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering
}
/**
* Gets administrative group value.
* Returns administrative group value.
*
* @return administrative group value
*/
......@@ -58,7 +58,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering
}
/**
* Gets administrative group value.
* Returns administrative group value.
*
* @return administrativeGroup value
*/
......@@ -93,7 +93,7 @@ public class AdministrativeGroup extends TlvHeader implements TrafficEngineering
}
/**
* Gets administrative group body as byte array.
* Returns administrative group body as byte array.
*
* @return byte array of sub tlv administrative group
*/
......
......@@ -31,7 +31,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub
/**
* Creates an instance of maximum bandwidth.
*
* @param header tlv header instance
* @param header TLV header instance
*/
public MaximumBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
......@@ -48,7 +48,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub
}
/**
* Gets value of maximum bandwidth.
* Returns value of maximum bandwidth.
*
* @return maximumBandwidth value of maximum bandwidth
*/
......@@ -69,7 +69,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub
}
/**
* Gets byte array of maximum bandwidth sub tlv.
* Returns byte array of maximum bandwidth sub tlv.
*
* @return byte array of maximum bandwidth sub tlv
*/
......@@ -83,7 +83,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub
}
/**
* Gets maximum bandwidth sub tlv byte array.
* Returns maximum bandwidth sub tlv byte array.
*
* @return byte array of maximum bandwidth sub tlv
*/
......@@ -92,7 +92,7 @@ public class MaximumBandwidth extends TlvHeader implements TrafficEngineeringSub
linkSubTypeBody = IsisUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth));
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("maximumBandwidth", maximumBandwidth)
......
......@@ -31,7 +31,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi
/**
* Creates an instance of maximum reservable bandwidth.
*
* @param header tlv header
* @param header TLV header
*/
public MaximumReservableBandwidth(TlvHeader header) {
this.setTlvType(header.tlvType());
......@@ -48,7 +48,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi
}
/**
* Gets value of maximum reversible bandwidth.
* Returns value of maximum reversible bandwidth.
*
* @return maximumBandwidth maximum reversible bandwidth
*/
......@@ -84,7 +84,7 @@ public class MaximumReservableBandwidth extends TlvHeader implements TrafficEngi
}
/**
* Gets maximum reservable bandwidth sub tlv body as byte array.
* Returns maximum reservable bandwidth sub tlv body as byte array.
*
* @return byte of maximum reservable bandwidth sub tlv body
*/
......
......@@ -51,7 +51,7 @@ public enum SubTlvType {
}
/**
* Gets the enum instance from type value - reverse lookup purpose.
* Returns the enum instance from type value - reverse lookup purpose.
*
* @param subTlvTypeValue TLV type value
* @return ISIS sub TLV type instance
......@@ -61,7 +61,7 @@ public enum SubTlvType {
}
/**
* Gets value.
* Returns value.
*
* @return value
*/
......
......@@ -47,7 +47,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine
}
/**
* Gets TE metric value.
* Returns TE metric value.
*
* @return value of traffic engineering metric
*/
......@@ -67,7 +67,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine
}
/**
* Gets instance as byte array.
* Returns instance as byte array.
*
* @return instance as byte array
*/
......@@ -82,7 +82,7 @@ public class TrafficEngineeringMetric extends TlvHeader implements TrafficEngine
}
/**
* Gets trafficEngineeringMetric as byte array .
* Returns trafficEngineeringMetric as byte array .
*
* @return byte array of trafficEngineeringMetric
*/
......
......@@ -50,7 +50,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering
}
/**
* Gets list of un reserved bandwidth .
* Returns list of un reserved bandwidth .
*
* @return List of un reserved bandwidth
*/
......@@ -71,7 +71,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering
}
/**
* Gets instance as byte array.
* Returns instance as byte array.
*
* @return instance as byte array
*/
......@@ -86,7 +86,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering
}
/**
* Gets unreserved bandwidth as byte array.
* Returns unreserved bandwidth as byte array.
*
* @return unreserved bandwidth as byte array
*/
......
......@@ -32,6 +32,7 @@ public class ChecksumCalculator {
* @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;
......
/*
* 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 com.fasterxml.jackson.databind.JsonNode;
/**
* Representation of ISIS config.
*/
public enum IsisConfig {
INSTANCE;
private JsonNode jsonNodes = null;
/**
* Returns the config value.
*
* @return jsonNodes json node
*/
public JsonNode config() {
return jsonNodes;
}
/**
* Sets the config value for jsonNode.
*
* @param jsonNodes json node
*/
public void setConfig(JsonNode jsonNodes) {
this.jsonNodes = jsonNodes;
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
package org.onosproject.isis.io.util;
/**
* Representation of ISIS constants.
* Representation of ISIS Constants.
*/
public final class IsisConstants {
public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC
......
/*
* 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 org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisNeighbor;
import org.onosproject.isis.controller.IsisNetworkType;
import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
import org.onosproject.isis.io.isispacket.tlv.HostNameTlv;
import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv;
import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv;
import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv;
import org.onosproject.isis.io.isispacket.tlv.MetricOfInternalReachability;
import org.onosproject.isis.io.isispacket.tlv.MetricsOfReachability;
import org.onosproject.isis.io.isispacket.tlv.ProtocolSupportedTlv;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import java.util.List;
/**
* Representation of link state PDU generator.
*/
public class LspGenerator {
public LsPdu getLsp(IsisInterface isisInterface, String lspId, IsisPduType isisPduType,
List<Ip4Address> allConfiguredInterfaceIps) {
IsisHeader header = getHeader(isisPduType);
LsPdu lsp = new LsPdu(header);
lsp.setPduLength(0);
lsp.setRemainingLifeTime(IsisConstants.LSPMAXAGE);
lsp.setLspId(lspId);
lsp.setSequenceNumber(isisInterface.isisLsdb().lsSequenceNumber(isisPduType));
lsp.setCheckSum(0);
if (isisPduType == IsisPduType.L1LSPDU) {
lsp.setTypeBlock((byte) 1);
lsp.setIntermediateSystemType((byte) 1);
} else if (isisPduType == IsisPduType.L2LSPDU) {
lsp.setTypeBlock((byte) 3);
lsp.setIntermediateSystemType((byte) 3);
}
lsp.setAttachedToOtherAreas(AttachedToOtherAreas.NONE);
lsp.setPartitionRepair(false);
lsp.setLspDbol(false);
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
tlvHeader.setTlvLength(0);
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(isisInterface.areaAddress());
lsp.addTlv(areaAddressTlv);
tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
tlvHeader.setTlvLength(0);
ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED);
lsp.addTlv(protocolSupportedTlv);
tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
tlvHeader.setTlvLength(0);
IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
for (Ip4Address ipaddress : allConfiguredInterfaceIps) {
ipInterfaceAddressTlv.addInterfaceAddres(ipaddress);
}
lsp.addTlv(ipInterfaceAddressTlv);
tlvHeader.setTlvType(TlvType.HOSTNAME.value());
tlvHeader.setTlvLength(0);
HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader);
hostNameTlv.setHostName(isisInterface.intermediateSystemName());
lsp.addTlv(hostNameTlv);
tlvHeader.setTlvType(TlvType.ISREACHABILITY.value());
tlvHeader.setTlvLength(0);
IsReachabilityTlv isReachabilityTlv = new IsReachabilityTlv(tlvHeader);
isReachabilityTlv.setReserved(0);
MetricsOfReachability metricsOfReachability = new MetricsOfReachability();
metricsOfReachability.setDefaultMetric((byte) 10);
metricsOfReachability.setDefaultIsInternal(true);
metricsOfReachability.setDelayMetric((byte) 10);
metricsOfReachability.setDelayIsInternal(true);
metricsOfReachability.setDelayMetricSupported(true);
metricsOfReachability.setExpenseMetric((byte) 10);
metricsOfReachability.setExpenseIsInternal(true);
metricsOfReachability.setExpenseMetricSupported(true);
metricsOfReachability.setErrorMetric((byte) 10);
metricsOfReachability.setErrorIsInternal(true);
metricsOfReachability.setErrorMetricSupported(true);
if (isisInterface.networkType() == IsisNetworkType.BROADCAST) {
if (isisPduType == IsisPduType.L1LSPDU) {
metricsOfReachability.setNeighborId(isisInterface.l1LanId());
} else if (isisPduType == IsisPduType.L2LSPDU) {
metricsOfReachability.setNeighborId(isisInterface.l2LanId());
}
} else if (isisInterface.networkType() == IsisNetworkType.P2P) {
MacAddress neighborMac = isisInterface.neighbors().iterator().next();
IsisNeighbor neighbor = isisInterface.lookup(neighborMac);
metricsOfReachability.setNeighborId(neighbor.neighborSystemId());
}
isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
lsp.addTlv(isReachabilityTlv);
tlvHeader.setTlvType(TlvType.IPINTERNALREACHABILITY.value());
tlvHeader.setTlvLength(0);
IpInternalReachabilityTlv ipInterReacTlv = new IpInternalReachabilityTlv(tlvHeader);
MetricOfInternalReachability metricOfIntRea = new MetricOfInternalReachability();
metricOfIntRea.setDefaultMetric((byte) 10);
metricOfIntRea.setDefaultIsInternal(true);
metricOfIntRea.setDefaultDistributionDown(true);
metricOfIntRea.setDelayMetric((byte) 0);
metricOfIntRea.setDelayMetricSupported(false);
metricOfIntRea.setDelayIsInternal(true);
metricOfIntRea.setExpenseMetric((byte) 0);
metricOfIntRea.setExpenseMetricSupported(false);
metricOfIntRea.setExpenseIsInternal(true);
metricOfIntRea.setErrorMetric((byte) 0);
metricOfIntRea.setErrorMetricSupported(false);
metricOfIntRea.setExpenseIsInternal(true);
metricOfIntRea.setIpAddress(isisInterface.interfaceIpAddress());
metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask()));
ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
lsp.addTlv(ipInterReacTlv);
return lsp;
}
public IsisHeader getHeader(IsisPduType pduType) {
IsisHeader isisHeader = new IsisHeader();
isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value()));
isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
isisHeader.setIsisPduType(pduType.value());
isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
isisHeader.setReserved((byte) IsisConstants.RESERVED);
isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
return isisHeader;
}
}
\ No newline at end of file