Kiran Ramachandra
Committed by Gerrit Code Review

ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding

Change-Id: Ic37fcf98dfb6c7a15a124b495aee8517a8df23c9
Showing 31 changed files with 3219 additions and 0 deletions
/*
* Copyright 2016 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.ospf.protocol.lsa;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.onosproject.ospf.protocol.util.OspfUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of a TLV header.
*/
public class TlvHeader {
private int tlvType;
private int tlvLength;
/**
* Gets TLV length.
*
* @return TLV length
*/
public int tlvLength() {
return tlvLength;
}
/**
* Sets TLV length.
*
* @param tlvLength TLV length
*/
public void setTlvLength(int tlvLength) {
this.tlvLength = tlvLength;
}
/**
* Gets TLV type.
*
* @return TLV type
*/
public int tlvType() {
return tlvType;
}
/**
* Sets TLV type.
*
* @param tlvType TLV type
*/
public void setTlvType(int tlvType) {
this.tlvType = tlvType;
}
/**
* Gets TLV header as bytes.
*
* @return TLV header as bytes
*/
public byte[] getTlvHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList();
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvType)));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvLength)));
return Bytes.toArray(headerLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("tlvType", tlvType)
.add("tlvLength", tlvLength)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
/**
* Representation of an administrative group value of link tlv of Traffic Engineering..
*/
public class AdministrativeGroup extends TlvHeader implements LinkSubType {
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(OspfUtil.byteToInteger(tempByteArray));
}
/**
* Returns administrative group as byte array.
*
* @return administrative group instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets administrative group body as byte array.
*
* @return byte array of sub tlv administrative group
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
byte[] linkSubTypeBody;
linkSubTypeBody = OspfUtil.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 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
/**
* Representation of link id value of link tlv of Traffic Engineering.
*/
public class LinkId extends TlvHeader implements LinkSubType {
private static final Logger log =
LoggerFactory.getLogger(LinkId.class);
private String linkId;
/**
* Creates an instance of link id.
*
* @param header tlv header instance
*/
public LinkId(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Sets link type.
*
* @param linkType link type value
*/
public void setLinkId(String linkType) {
this.linkId = linkType;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing packet
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setLinkId(InetAddress.getByAddress(tempByteArray).getHostName());
} catch (Exception e) {
log.debug("Error::LinkId:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
/**
* Returns instance as byte array.
*
* @return instance as bytes
* @throws Exception might throws exception while parsing packet
*/
public byte[] asBytes() throws Exception {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets byte array of link id sub tlv body.
*
* @return gets the body as byte array
* @throws Exception might throws exception while parsing packet
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
byte[] linkSubTypeBody = null;
try {
linkSubTypeBody = InetAddress.getByName(this.linkId).getAddress();
} catch (Exception e) {
log.debug("Error::LinkId:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
return linkSubTypeBody;
}
/**
* Returns this instance as string.
*
* @return this instance as string
*/
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("linkId", linkId)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
/**
* Marker interface to represent TE Link sub types.
*/
public interface LinkSubType {
}
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
/**
* Representation of TE link sub types.
*/
public enum LinkSubTypes {
LINK_TYPE(1),
LINK_ID(2),
LOCAL_INTERFACE_IP_ADDRESS(3),
REMOTE_INTERFACE_IP_ADDRESS(4),
TRAFFIC_ENGINEERING_METRIC(5),
MAXIMUM_BANDWIDTH(6),
MAXIMUM_RESERVABLE_BANDWIDTH(7),
UNRESERVED_BANDWIDTH(8),
ADMINISTRATIVE_GROUP(9);
private int value;
/**
* Creates an instance of link sub types.
*
* @param value link sub type value
*/
LinkSubTypes(int value) {
this.value = value;
}
/**
* Gets the link sub type value.
*
* @return link sub type value
*/
public int value() {
return value;
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Representation of link type TE value.
*/
public class LinkType extends TlvHeader implements LinkSubType {
private static final Logger log =
LoggerFactory.getLogger(LinkType.class);
private int linkType;
/**
* Creates link type instance .
*/
public LinkType() {
}
/**
* Creates link type instance.
*
* @param header tlv header instance
*/
public LinkType(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Sets link type.
*
* @param linkType value of link type
*/
public void setLinkType(int linkType) {
this.linkType = linkType;
}
/**
* Reads from channel buffer.
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
try {
int len = channelBuffer.readableBytes();
byte[] tempByteArray = new byte[len];
channelBuffer.readBytes(tempByteArray, 0, len);
this.setLinkType(OspfUtil.byteToInteger(tempByteArray));
} catch (Exception e) {
log.debug("Error::LinkType:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
/**
* Gets link subtype as byte array.
*
* @return byte array of link subtype
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets link subtype as bytes.
*
* @return byte array of link subtype
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
byte[] linkSubTypeBody = new byte[4];
linkSubTypeBody[0] = (byte) this.linkType;
linkSubTypeBody[1] = 0;
linkSubTypeBody[2] = 0;
linkSubTypeBody[3] = 0;
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("linkType", linkType)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of local interface ip address TE value.
*/
public class LocalInterfaceIpAddress extends TlvHeader implements LinkSubType {
private static final Logger log =
LoggerFactory.getLogger(RemoteInterfaceIpAddress.class);
private List<String> localInterfaceIPAddress = new ArrayList<>();
/**
* Creates an instance of local interface ip address.
*
* @param header tlv header instance
*/
public LocalInterfaceIpAddress(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Adds local interface ip address.
*
* @param localAddress ip address
*/
public void addLocalInterfaceIPAddress(String localAddress) {
localInterfaceIPAddress.add(localAddress);
}
/**
* Gets local interface ip address.
*
* @return localAddress ip address
*/
public List<String> getLocalInterfaceIPAddress() {
return localInterfaceIPAddress;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.addLocalInterfaceIPAddress(InetAddress.getByAddress(tempByteArray).getHostName());
} catch (Exception e) {
log.debug("Error::readFrom:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
}
/**
* Gets local interface ip address as byte array.
*
* @return local interface ip address as byte array
* @throws Exception might throws exception while parsing packet
*/
public byte[] asBytes() throws Exception {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets byte array of local interface ip address.
*
* @return byte array of local interface ip address
* @throws Exception might throws exception while parsing packet
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
List<Byte> linkSubTypeBody = new ArrayList<>();
for (String remoteAddress : this.localInterfaceIPAddress) {
try {
linkSubTypeBody.addAll(Bytes.asList(InetAddress.getByName(remoteAddress).getAddress()));
} catch (Exception e) {
log.debug("Error::getLinkSubTypeTlvBodyAsByteArray:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
return Bytes.toArray(linkSubTypeBody);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("localInterfaceIPAddress", localInterfaceIPAddress)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
/**
* Representation of maximum bandwidth TE value.
*/
public class MaximumBandwidth extends TlvHeader implements LinkSubType {
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 = (OspfUtil.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 = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets maximum bandwidth sub tlv byte array.
*
* @return byte array of maximum bandwidth sub tlv
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
byte[] linkSubTypeBody;
linkSubTypeBody = OspfUtil.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 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
/**
* Representation of maximum reservable bandwidth TE value.
*/
public class MaximumReservableBandwidth extends TlvHeader implements LinkSubType {
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 = (OspfUtil.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 = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinksubTypeTlvBodyAsByteArray();
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[] getLinksubTypeTlvBodyAsByteArray() {
byte[] linkSubTypeBody;
linkSubTypeBody = OspfUtil.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 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of remote interface ip address TE value.
*/
public class RemoteInterfaceIpAddress extends TlvHeader implements LinkSubType {
private static final Logger log =
LoggerFactory.getLogger(RemoteInterfaceIpAddress.class);
private List<String> remoteInterfaceAddress = new ArrayList<>();
/**
* Creates an instance of remote interface ip address.
*
* @param header tlv header instance
*/
public RemoteInterfaceIpAddress(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Adds remote interface ip address.
*
* @param remoteAddress ip address
*/
public void addRemoteInterfaceAddress(String remoteAddress) {
remoteInterfaceAddress.add(remoteAddress);
}
/**
* Gets remote interface ip address.
*
* @return remoteAddress ip address
*/
public List<String> getRemoteInterfaceAddress() {
return remoteInterfaceAddress;
}
/**
* Reads bytes from channel buffer .
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing packet
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.addRemoteInterfaceAddress(InetAddress.getByAddress(tempByteArray).getHostName());
} catch (Exception e) {
log.debug("Error::RemoteInterfaceIPAddress:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
}
/**
* Gets byte array of remote interface ip address .
*
* @return byte array of remote interface ip address
* @throws Exception might throws exception while parsing packet
*/
public byte[] asBytes() throws Exception {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets byte array of remote interface ip address.
*
* @return byte array of remote interface ip address
* @throws Exception might throws exception while parsing packet
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
List<Byte> linkSubTypeBody = new ArrayList<>();
for (String remoteAddress : this.remoteInterfaceAddress) {
try {
linkSubTypeBody.addAll(Bytes.asList(InetAddress.getByName(remoteAddress).getAddress()));
} catch (Exception e) {
log.debug("Error::RemoteInterfaceIPAddress:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
return Bytes.toArray(linkSubTypeBody);
}
/**
* Returns instance as string.
*
* @return instance as string
*/
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("RemoteInterfaceIPAddress", remoteInterfaceAddress)
.toString();
}
}
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
/**
* Representation of traffic engineering metric TE value.
*/
public class TrafficEngineeringMetric extends TlvHeader implements LinkSubType {
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(OspfUtil.byteToLong(tempByteArray));
}
/**
* Gets instance as byte array.
*
* @return instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets trafficEngineeringMetric as byte array .
*
* @return byte array of trafficEngineeringMetric
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
byte[] linkSubTypeBody;
linkSubTypeBody = OspfUtil.convertToFourBytes(this.trafficEngineeringMetric);
return linkSubTypeBody;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("trafficEngineeringMetric", trafficEngineeringMetric)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
/**
* Representation of an unknown or experimental TE value.
*/
public class UnknownLinkSubType extends TlvHeader implements LinkSubType {
private byte[] value;
/**
* Creates an instance of this.
*
* @param header tlv header
*/
public UnknownLinkSubType(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Gets the unknown subtype value .
*
* @return unknown subtype value
*/
public byte[] value() {
return value;
}
/**
* Sets unknown subtype value.
*
* @param value unknown subtype value.
*/
public void setValue(byte[] value) {
this.value = value;
}
/**
* 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.setValue(tempByteArray);
}
/**
* Returns instance as byte array.
*
* @return instance as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets instance body as byte array.
*
* @return instance body as byte array
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
return value;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("value", value)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.util.OspfParameters;
import org.onosproject.ospf.protocol.util.OspfUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an unreserved band width TE value.
*/
public class UnreservedBandwidth extends TlvHeader implements LinkSubType {
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() >= OspfUtil.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 = getTlvHeaderAsByteArray();
byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Gets unreserved bandwidth as byte array.
*
* @return unreserved bandwidth as byte array
*/
public byte[] getLinkSubTypeTlvBodyAsByteArray() {
List<Byte> linkSubTypeBody = new ArrayList<>();
if (this.unReservedBandwidth.size() < 8) {
int size = OspfUtil.EIGHT_BYTES - this.unReservedBandwidth.size();
for (int i = 0; i < size; i++) {
linkSubTypeBody.addAll(Bytes.asList(OspfUtil.convertToFourBytes(OspfParameters.INITIAL_BANDWIDTH)));
}
}
for (Float unreservedBandwidth : this.unReservedBandwidth) {
int unresBandwidth = Float.floatToIntBits(unreservedBandwidth);
linkSubTypeBody.addAll(Bytes.asList(OspfUtil.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 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 ospf TE link types.
*/
package org.onosproject.ospf.protocol.lsa.linksubtype;
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.tlvtypes;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.lsa.linksubtype.AdministrativeGroup;
import org.onosproject.ospf.protocol.lsa.linksubtype.LinkId;
import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubType;
import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubTypes;
import org.onosproject.ospf.protocol.lsa.linksubtype.LinkType;
import org.onosproject.ospf.protocol.lsa.linksubtype.LocalInterfaceIpAddress;
import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumBandwidth;
import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumReservableBandwidth;
import org.onosproject.ospf.protocol.lsa.linksubtype.RemoteInterfaceIpAddress;
import org.onosproject.ospf.protocol.lsa.linksubtype.TrafficEngineeringMetric;
import org.onosproject.ospf.protocol.lsa.linksubtype.UnknownLinkSubType;
import org.onosproject.ospf.protocol.lsa.linksubtype.UnreservedBandwidth;
import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
import org.onosproject.ospf.protocol.util.OspfUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an OSPF Opaque link tlv.
*/
public class LinkTlv extends TlvHeader implements TopLevelTlv {
private List<LinkSubType> subTlv = new ArrayList<>();
/**
* Creates an instance of link tlv.
*
* @param header tlv header
*/
public LinkTlv(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Gets sub tlv lists.
*
* @return sub tlv lists
*/
public List<LinkSubType> subTlvList() {
return this.subTlv;
}
/**
* Reads bytes from channel buffer .
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing packet
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
while (channelBuffer.readableBytes() > 0) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readUnsignedShort());
tlvHeader.setTlvLength(channelBuffer.readUnsignedShort());
if (LinkSubTypes.LINK_TYPE.value() == tlvHeader.tlvType()) {
LinkType linktype = new LinkType(tlvHeader);
linktype.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(linktype);
if (tlvHeader.tlvLength() < OspfUtil.FOUR_BYTES) {
int readerIndex = channelBuffer.readerIndex() + (OspfUtil.FOUR_BYTES - tlvHeader.tlvLength());
channelBuffer.readerIndex(readerIndex);
}
} else if (LinkSubTypes.LINK_ID.value() == tlvHeader.tlvType()) {
LinkId linkId = new LinkId(tlvHeader);
linkId.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(linkId);
} else if (LinkSubTypes.LOCAL_INTERFACE_IP_ADDRESS.value() == tlvHeader.tlvType()) {
LocalInterfaceIpAddress localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
localInterfaceIpAddress.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(localInterfaceIpAddress);
} else if (LinkSubTypes.REMOTE_INTERFACE_IP_ADDRESS.value() == tlvHeader.tlvType()) {
RemoteInterfaceIpAddress remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
remoteInterfaceIpAddress.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(remoteInterfaceIpAddress);
} else if (LinkSubTypes.TRAFFIC_ENGINEERING_METRIC.value() == tlvHeader.tlvType()) {
TrafficEngineeringMetric trafficEngineeringMetric = new TrafficEngineeringMetric(tlvHeader);
trafficEngineeringMetric.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(trafficEngineeringMetric);
} else if (LinkSubTypes.MAXIMUM_BANDWIDTH.value() == tlvHeader.tlvType()) {
MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
maximumBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(maximumBandwidth);
} else if (LinkSubTypes.MAXIMUM_RESERVABLE_BANDWIDTH.value() == tlvHeader.tlvType()) {
MaximumReservableBandwidth maximumReservableBandwidth = new MaximumReservableBandwidth(tlvHeader);
maximumReservableBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(maximumReservableBandwidth);
} else if (LinkSubTypes.UNRESERVED_BANDWIDTH.value() == tlvHeader.tlvType()) {
UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
unreservedBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(unreservedBandwidth);
} else if (LinkSubTypes.ADMINISTRATIVE_GROUP.value() == tlvHeader.tlvType()) {
AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
administrativeGroup.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(administrativeGroup);
} else {
UnknownLinkSubType unknownLinkSubType = new UnknownLinkSubType(tlvHeader);
unknownLinkSubType.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
subTlv.add(unknownLinkSubType);
}
}
}
/**
* Gets link tlv as byte array.
*
* @return link tlv as byte array
* @throws Exception might throws exception while parsing buffer
*/
public byte[] asBytes() throws Exception {
byte[] lsaMessage = null;
byte[] tlvHeader = getTlvHeaderAsByteArray();
byte[] tlvBody = getTlvBodyAsByteArray();
lsaMessage = Bytes.concat(tlvHeader, tlvBody);
return lsaMessage;
}
/**
* Gets tlv body as byte array.
*
* @return tlv body as byte array
* @throws Exception might throws exception while parsing buffer
*/
public byte[] getTlvBodyAsByteArray() throws Exception {
List<Byte> bodyLst = new ArrayList<>();
for (LinkSubType tlv : subTlv) {
//Check the type of tlv and build bytes accordingly
if (tlv instanceof LinkType) {
LinkType linkType = (LinkType) tlv;
bodyLst.addAll(Bytes.asList(linkType.asBytes()));
} else if (tlv instanceof LinkId) {
LinkId linkId = (LinkId) tlv;
bodyLst.addAll(Bytes.asList(linkId.asBytes()));
} else if (tlv instanceof LocalInterfaceIpAddress) {
LocalInterfaceIpAddress localInterfaceIpAddress = (LocalInterfaceIpAddress) tlv;
bodyLst.addAll(Bytes.asList(localInterfaceIpAddress.asBytes()));
} else if (tlv instanceof RemoteInterfaceIpAddress) {
RemoteInterfaceIpAddress remoteInterfaceIpAddress = (RemoteInterfaceIpAddress) tlv;
bodyLst.addAll(Bytes.asList(remoteInterfaceIpAddress.asBytes()));
} else if (tlv instanceof TrafficEngineeringMetric) {
TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) tlv;
bodyLst.addAll(Bytes.asList(trafficEngineeringMetric.asBytes()));
} else if (tlv instanceof MaximumBandwidth) {
MaximumBandwidth maximumBandwidth = (MaximumBandwidth) tlv;
bodyLst.addAll(Bytes.asList(maximumBandwidth.asBytes()));
} else if (tlv instanceof MaximumReservableBandwidth) {
MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) tlv;
bodyLst.addAll(Bytes.asList(maximumReservableBandwidth.asBytes()));
} else if (tlv instanceof UnreservedBandwidth) {
UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) tlv;
bodyLst.addAll(Bytes.asList(unreservedBandwidth.asBytes()));
} else if (tlv instanceof AdministrativeGroup) {
AdministrativeGroup administrativeGroup = (AdministrativeGroup) tlv;
bodyLst.addAll(Bytes.asList(administrativeGroup.asBytes()));
} else {
UnknownLinkSubType unknownLinkSubType = (UnknownLinkSubType) tlv;
bodyLst.addAll(Bytes.asList(unknownLinkSubType.asBytes()));
}
}
return Bytes.toArray(bodyLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("subTlv", subTlv)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.tlvtypes;
/**
* Representation of an OSPF Opaque top level tlv types.
*/
public enum OpaqueTopLevelTlvTypes {
ROUTER(1),
LINK(2);
private int value;
/**
* Creates an instance of Opaque top level tlv types.
*
* @param value
*/
OpaqueTopLevelTlvTypes(int value) {
this.value = value;
}
/**
* Gets the tlv type value.
*
* @return tlv type value
*/
public int value() {
return value;
}
}
/*
* Copyright 2016 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.ospf.protocol.lsa.tlvtypes;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an OSPF Opaque router tlv.
*/
public class RouterTlv extends TlvHeader implements TopLevelTlv {
private static final Logger log =
LoggerFactory.getLogger(RouterTlv.class);
private Ip4Address routerAddress;
/**
* Creates an instance of Opaque router tlv.
*
* @param header tlv header
*/
public RouterTlv(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Gets router address.
*
* @return router address
*/
public Ip4Address routerAddress() {
return routerAddress;
}
/**
* Sets router address.
*
* @param routerAddress router address.
*/
public void setRouterAddress(Ip4Address routerAddress) {
this.routerAddress = routerAddress;
}
/**
* Reads bytes from channel buffer .
*
* @param channelBuffer channel buffer instance
* @throws Exception might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws Exception {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setRouterAddress(Ip4Address.valueOf(tempByteArray));
} catch (Exception e) {
log.debug("Error::RouterTLV:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
}
}
/**
* Gets router tlv as byte array.
*
* @return router tlv as byte array
*/
public byte[] asBytes() {
byte[] lsaMessage = null;
byte[] tlvHeader = getTlvHeaderAsByteArray();
byte[] tlvBody = getTlvBodyAsByteArray();
lsaMessage = Bytes.concat(tlvHeader, tlvBody);
return lsaMessage;
}
/**
* Gets tlv body as byte array.
*
* @return tlv body as byte array
*/
public byte[] getTlvBodyAsByteArray() {
List<Byte> bodyLst = new ArrayList<>();
bodyLst.addAll(Bytes.asList(this.routerAddress().toOctets()));
return Bytes.toArray(bodyLst);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("routerAddress", routerAddress)
.toString();
}
}
/*
* Copyright 2016 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 OSPF Opaque Tlv Types.
*/
package org.onosproject.ospf.protocol.lsa.tlvtypes;
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/**
* Unit test class for Tlv Header.
*/
public class TlvHeaderTest {
private TlvHeader tlvHeader;
private byte[] result;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
result = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(tlvHeader.toString(), is(notNullValue()));
}
/**
* Tests tlvLength() getter method.
*/
@Test
public void testGetTlvLength() throws Exception {
tlvHeader.setTlvLength(2);
assertThat(tlvHeader.tlvLength(), is(2));
}
/**
* Tests tlvLength() setter method.
*/
@Test
public void testSetTlvLength() throws Exception {
tlvHeader.setTlvLength(2);
assertThat(tlvHeader.tlvLength(), is(2));
}
/**
* Tests tlvType() getter method.
*/
@Test
public void testGetTlvType() throws Exception {
tlvHeader.setTlvType(2);
assertThat(tlvHeader.tlvType(), is(2));
}
/**
* Tests tlvType() setter method.
*/
@Test
public void testSetTlvType() throws Exception {
tlvHeader.setTlvType(2);
assertThat(tlvHeader.tlvType(), is(2));
}
/**
* Tests getTlvHeaderAsByteArray() method.
*/
@Test
public void testGetTlvHeaderAsByteArray() throws Exception {
result = tlvHeader.getTlvHeaderAsByteArray();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for AdministrativeGroup.
*/
public class AdministrativeGroupTest {
private final byte[] packet = {0, 0, 0, 1};
private AdministrativeGroup administrativeGroup;
private ChannelBuffer channelBuffer;
private TlvHeader tlvHeader;
private byte[] result;
@Before
public void setUp() throws Exception {
administrativeGroup = new AdministrativeGroup(new TlvHeader());
}
@After
public void tearDown() throws Exception {
administrativeGroup = null;
channelBuffer = null;
tlvHeader = null;
}
/**
* Tests administrativeGroup() getter method.
*/
@Test
public void testGetAdministrativeGroup() throws Exception {
administrativeGroup.setAdministrativeGroup(1);
assertThat(administrativeGroup.administrativeGroup(), is(1));
}
/**
* Tests administrativeGroup() setter method.
*/
@Test
public void testSetAdministrativeGroup() throws Exception {
administrativeGroup.setAdministrativeGroup(1);
assertThat(administrativeGroup.administrativeGroup(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(9);
tlvHeader.setTlvLength(4);
administrativeGroup = new AdministrativeGroup(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
administrativeGroup.readFrom(channelBuffer);
assertThat(administrativeGroup.administrativeGroup(), is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = administrativeGroup.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = administrativeGroup.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(administrativeGroup.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for LinkId.
*/
public class LinkIdTest {
private final byte[] packet = {1, 1, 1, 1};
private final byte[] packet1 = {0, 0, 1};
private LinkId linkId;
private TlvHeader tlvHeader;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
linkId = new LinkId(new TlvHeader());
}
@After
public void tearDown() throws Exception {
linkId = null;
channelBuffer = null;
tlvHeader = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(linkId.toString(), is(notNullValue()));
}
/**
* Tests linkId() getter method.
*/
@Test
public void testGetLinkId() throws Exception {
linkId.setLinkId("1.1.1.1");
assertThat(linkId, is(notNullValue()));
}
/**
* Tests linkId() setter method.
*/
@Test
public void testSetLinkId() throws Exception {
linkId.setLinkId("1.1.1.1");
assertThat(linkId, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(2);
tlvHeader.setTlvLength(4);
linkId = new LinkId(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
linkId.readFrom(channelBuffer);
assertThat(linkId, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(2);
tlvHeader.setTlvLength(4);
linkId = new LinkId(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
linkId.readFrom(channelBuffer);
assertThat(linkId, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = linkId.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = linkId.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for LinkType.
*/
public class LinkTypeTest {
private final byte[] packet = {0, 0, 0, 1};
private final byte[] packet1 = {0, 0, 1};
private LinkType linkType;
private byte[] result;
private ChannelBuffer channelBuffer;
private TlvHeader tlvHeader;
@Before
public void setUp() throws Exception {
linkType = new LinkType();
}
@After
public void tearDown() throws Exception {
linkType = null;
channelBuffer = null;
tlvHeader = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(linkType.toString(), is(notNullValue()));
}
/**
* Tests linkType() getter method.
*/
@Test
public void testGetLinkType() throws Exception {
linkType.setLinkType(1);
assertThat(linkType, is(notNullValue()));
}
/**
* Tests linkType() setter method.
*/
@Test
public void testSetLinkType() throws Exception {
linkType.setLinkType(1);
assertThat(linkType, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(1);
tlvHeader.setTlvLength(4);
linkType = new LinkType(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
linkType.readFrom(channelBuffer);
assertThat(linkType, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom1() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(1);
tlvHeader.setTlvLength(4);
linkType = new LinkType(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
linkType.readFrom(channelBuffer);
assertThat(linkType, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = linkType.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = linkType.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for LocalInterfaceIpAddress.
*/
public class LocalInterfaceIpAddressTest {
private final byte[] packet = {1, 1, 1, 1};
private final byte[] packet1 = {};
private LocalInterfaceIpAddress localInterfaceIpAddress;
private TlvHeader tlvHeader;
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
localInterfaceIpAddress = new LocalInterfaceIpAddress(new TlvHeader());
}
@After
public void tearDown() throws Exception {
localInterfaceIpAddress = null;
tlvHeader = null;
result = null;
channelBuffer = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(localInterfaceIpAddress.toString(), is(notNullValue()));
}
/**
* Tests addLocalInterfaceIPAddress() method.
*/
@Test
public void testAddLocalInterfaceIPAddress() throws Exception {
localInterfaceIpAddress.addLocalInterfaceIPAddress("1.1.1.1");
assertThat(localInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(3);
tlvHeader.setTlvLength(4);
localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
localInterfaceIpAddress.readFrom(channelBuffer);
assertThat(localInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom1() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(3);
tlvHeader.setTlvLength(4);
localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
localInterfaceIpAddress.readFrom(channelBuffer);
assertThat(localInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = localInterfaceIpAddress.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = localInterfaceIpAddress.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
}
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for MaximumBandwidth.
*/
public class MaximumBandwidthTest {
private final byte[] packet = {0, 0, 0, 0};
private MaximumBandwidth maximumBandwidth;
private TlvHeader header;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
maximumBandwidth = new MaximumBandwidth(new TlvHeader());
}
@After
public void tearDown() throws Exception {
maximumBandwidth = null;
header = null;
channelBuffer = null;
result = null;
}
/**
* Tests maximumBandwidth() setter method.
*/
@Test
public void testSetMaximumBandwidth() throws Exception {
maximumBandwidth.setMaximumBandwidth(123456.00f);
assertThat(maximumBandwidth, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvType(6);
header.setTlvLength(4);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
maximumBandwidth = new MaximumBandwidth(header);
maximumBandwidth.readFrom(channelBuffer);
assertThat(maximumBandwidth, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = maximumBandwidth.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(maximumBandwidth.toString(), is(notNullValue()));
}
}
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for MaximumReservableBandwidth.
*/
public class MaximumReservableBandwidthTest {
private final byte[] packet = {0, 0, 0, 0};
private MaximumReservableBandwidth maximumReservableBandwidth;
private TlvHeader header;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
maximumReservableBandwidth = new MaximumReservableBandwidth(new TlvHeader());
}
@After
public void tearDown() throws Exception {
maximumReservableBandwidth = null;
header = null;
channelBuffer = null;
result = null;
}
/**
* Tests maximumBandwidth() setter method.
*/
@Test
public void testSetMaximumBandwidth() throws Exception {
maximumReservableBandwidth.setMaximumBandwidth(123456.78f);
assertThat(maximumReservableBandwidth, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvType(6);
header.setTlvLength(4);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
maximumReservableBandwidth = new MaximumReservableBandwidth(header);
maximumReservableBandwidth.readFrom(channelBuffer);
assertThat(maximumReservableBandwidth, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = maximumReservableBandwidth.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = maximumReservableBandwidth.getLinksubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(maximumReservableBandwidth.toString(), is(notNullValue()));
}
}
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for RemoteInterfaceIpAddress.
*/
public class RemoteInterfaceIpAddressTest {
private final byte[] packet = {1, 1, 1, 1};
private final byte[] packet1 = {};
private byte[] result;
private TlvHeader tlvHeader;
private RemoteInterfaceIpAddress remoteInterfaceIpAddress;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(new TlvHeader());
}
@After
public void tearDown() throws Exception {
remoteInterfaceIpAddress = null;
result = null;
tlvHeader = null;
channelBuffer = null;
}
/**
* Tests addRemoteInterfaceAddress() method.
*/
@Test
public void testAddRemoteInterfaceIpAddress() throws Exception {
remoteInterfaceIpAddress.addRemoteInterfaceAddress("1.1.1.1");
assertThat(remoteInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(4);
tlvHeader.setTlvLength(4);
remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
remoteInterfaceIpAddress.readFrom(channelBuffer);
assertThat(remoteInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom1() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(4);
tlvHeader.setTlvLength(4);
remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
remoteInterfaceIpAddress.readFrom(channelBuffer);
assertThat(remoteInterfaceIpAddress, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = remoteInterfaceIpAddress.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = remoteInterfaceIpAddress.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(remoteInterfaceIpAddress.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for TrafficEngineeringMetric.
*/
public class TrafficEngineeringMetricTest {
private final byte[] packet = {0, 0, 1, 1};
private TrafficEngineeringMetric trafficEngineeringMetric;
private TlvHeader header;
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
trafficEngineeringMetric = new TrafficEngineeringMetric(new TlvHeader());
}
@After
public void tearDown() throws Exception {
trafficEngineeringMetric = null;
header = null;
result = null;
channelBuffer = null;
}
/**
* Tests trafficEngineeringMetric() setter method.
*/
@Test
public void testSetTrafficEngineeringMetric() throws Exception {
trafficEngineeringMetric.setTrafficEngineeringMetric(123456789L);
assertThat(trafficEngineeringMetric, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvLength(4);
header.setTlvType(5);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
trafficEngineeringMetric = new TrafficEngineeringMetric(header);
trafficEngineeringMetric.readFrom(channelBuffer);
assertThat(trafficEngineeringMetric, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = trafficEngineeringMetric.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = trafficEngineeringMetric.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(trafficEngineeringMetric.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for UnknownLinkSubType.
*/
public class UnknownLinkSubTypeTest {
private final byte[] packet = {0, 114, 0, 4, 0, 0, 0, 1};
private UnknownLinkSubType unknownLinkSubType;
private TlvHeader header;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
unknownLinkSubType = new UnknownLinkSubType(new TlvHeader());
}
@After
public void tearDown() throws Exception {
unknownLinkSubType = null;
header = null;
}
/**
* Tests value() getter method.
*/
@Test
public void testValue() throws Exception {
unknownLinkSubType.setValue(packet);
assertThat(unknownLinkSubType.value(), is(notNullValue()));
}
/**
* Tests value() setter method.
*/
@Test
public void testSetValue() throws Exception {
unknownLinkSubType.setValue(packet);
assertThat(unknownLinkSubType.value(), is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(114);
unknownLinkSubType = new UnknownLinkSubType(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
unknownLinkSubType.readFrom(channelBuffer);
assertThat(unknownLinkSubType, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test(expected = Exception.class)
public void testAsBytes() throws Exception {
result = unknownLinkSubType.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(packet);
unknownLinkSubType.readFrom(channelBuffer);
result = unknownLinkSubType.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(unknownLinkSubType.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.linksubtype;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for OspfRouterId.
*/
public class UnreservedBandwidthTest {
private final byte[] packet = {0, 0, 0, 1};
private UnreservedBandwidth unreservedBandwidth;
private TlvHeader header;
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
unreservedBandwidth = new UnreservedBandwidth(new TlvHeader());
}
@After
public void tearDown() throws Exception {
unreservedBandwidth = null;
header = null;
result = null;
channelBuffer = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(unreservedBandwidth.toString(), is(notNullValue()));
}
/**
* Tests addUnReservedBandwidth() method.
*/
@Test
public void testAddUnReservedBandwidth() throws Exception {
unreservedBandwidth.addUnReservedBandwidth(123456.78f);
assertThat(unreservedBandwidth, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvLength(4);
header.setTlvType(8);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
unreservedBandwidth = new UnreservedBandwidth(header);
unreservedBandwidth.readFrom(channelBuffer);
unreservedBandwidth.readFrom(channelBuffer);
assertThat(unreservedBandwidth, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = unreservedBandwidth.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTLVBodyAsByteArray() throws Exception {
result = unreservedBandwidth.getLinkSubTypeTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.tlvtypes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
* Unit test class for LinkTlv.
*/
public class LinkTlvTest {
private final byte[] packet1 = {0, 9, 0, 4, 0, 0, 0, 1};
private final byte[] packet2 = {0, 1, 0, 4, 0, 0, 0, 1};
private final byte[] packet3 = {0, 2, 0, 4, 0, 0, 0, 1};
private final byte[] packet4 = {0, 3, 0, 4, 0, 0, 0, 1};
private final byte[] packet5 = {0, 4, 0, 4, 0, 0, 0, 1};
private final byte[] packet6 = {0, 6, 0, 4, 0, 0, 0, 1};
private final byte[] packet7 = {0, 7, 0, 4, 0, 0, 0, 1};
private final byte[] packet8 = {0, 8, 0, 4, 0, 0, 0, 1};
private final byte[] packet9 = {0, 9, 0, 4, 0, 0, 0, 1,
0, 9, 0, 4, 0, 0, 0, 1,
0, 1, 0, 4, 0, 0, 0, 1,
0, 2, 0, 4, 0, 0, 0, 1,
0, 3, 0, 4, 0, 0, 0, 1,
0, 4, 0, 4, 0, 0, 0, 1,
0, 6, 0, 4, 0, 0, 0, 1,
0, 7, 0, 4, 0, 0, 0, 1,
0, 8, 0, 4, 0, 0, 0, 1,
};
private LinkTlv linkTlv;
private TlvHeader header;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
linkTlv = new LinkTlv(new TlvHeader());
}
@After
public void tearDown() throws Exception {
linkTlv = null;
header = null;
channelBuffer = null;
result = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(linkTlv.toString(), is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(9);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(1);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet2);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(2);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet3);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(3);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet4);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(4);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet5);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(5);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(6);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet6);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(7);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet7);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(8);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet8);
linkTlv.readFrom(channelBuffer);
assertThat(linkTlv, is(notNullValue()));
assertThat(linkTlv, instanceOf(LinkTlv.class));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = linkTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getTlvBodyAsByteArray() method.
*/
@Test
public void testGetTlvBodyAsByteArray() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(packet9);
linkTlv.readFrom(channelBuffer);
result = linkTlv.getTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 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.ospf.protocol.lsa.tlvtypes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
* Unit test class for RouterTlv.
*/
public class RouterTlvTest {
private final byte[] packet = {1, 1, 1, 1};
private final byte[] packet1 = {1, 1, 1};
private RouterTlv rtlv;
private TlvHeader header;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
rtlv = new RouterTlv(new TlvHeader());
}
@After
public void tearDown() throws Exception {
rtlv = null;
header = null;
channelBuffer = null;
result = null;
}
/**
* Tests routerAddress() getter method.
*/
@Test
public void testGetRouterAddress() throws Exception {
rtlv.setRouterAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(rtlv.routerAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests routerAddress() setter method.
*/
@Test
public void testSetRouterAddress() throws Exception {
rtlv.setRouterAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(rtlv.routerAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
header = new TlvHeader();
header.setTlvType(1);
header.setTlvLength(4);
rtlv = new RouterTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
rtlv.readFrom(channelBuffer);
assertThat(rtlv, is(notNullValue()));
assertThat(rtlv, instanceOf(RouterTlv.class));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
header = new TlvHeader();
header.setTlvType(1);
header.setTlvLength(4);
rtlv = new RouterTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
rtlv.readFrom(channelBuffer);
assertThat(rtlv, is(notNullValue()));
assertThat(rtlv, instanceOf(RouterTlv.class));
}
/**
* Tests asBytes() method.
*/
@Test(expected = Exception.class)
public void testAsBytes() throws Exception {
result = rtlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getTlvBodyAsByteArray() method.
*/
@Test(expected = Exception.class)
public void testGetTLVBodyAsByteArray() throws Exception {
result = rtlv.getTlvBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(rtlv.toString(), is(notNullValue()));
}
}