PRASHANTH SHIVANANJAPPA
Committed by Gerrit Code Review

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

Change-Id: I0849d87ad1c7f9a8e08aabebd547dfd2dfde49df
Showing 31 changed files with 3658 additions and 92 deletions
/*
* 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.
*/
* 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.SubTlvType;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.util.IsisUtil;
import java.util.ArrayList;
......@@ -32,9 +28,7 @@ import java.util.List;
*/
public class IsExtendedReachability extends TlvHeader implements IsisTlv {
private String neighborId;
private int metric;
private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>();
private List<NeighborForExtendedIs> neighbors = new ArrayList<>();
/**
* Creates an instance of IP external reachability TLV.
......@@ -47,67 +41,20 @@ public class IsExtendedReachability extends TlvHeader implements IsisTlv {
}
/**
* Returns neighbor ID.
*
* @return neighbor ID
*/
public String neighborId() {
return neighborId;
}
/**
* Sets neighbor ID.
*
* @param neighborId neighbor ID
*/
public void setNeighborId(String neighborId) {
this.neighborId = neighborId;
}
/**
* Returns metric.
* Adds the neighbor for extended IS instance to IS extended reachability TLV.
*
* @return metric
* @param neighbor neighbor for extended IS instance
*/
public int metric() {
return metric;
}
/**
* Sets metric.
*
* @param metric metric
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Adds the traffic engineering sub TLV to IS extended reachability TLV.
*
* @param trafEnginSubTlv traffic engineering sub TLV
*/
public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) {
this.trafEnginSubTlv.add(trafEnginSubTlv);
public void addNeighbor(NeighborForExtendedIs neighbor) {
this.neighbors.add(neighbor);
}
@Override
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setNeighborId(IsisUtil.systemId(tempByteArray));
this.setMetric(channelBuffer.readUnsignedMedium());
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());
}
while (channelBuffer.readableBytes() >= IsisUtil.EIGHT_BYTES + IsisUtil.THREE_BYTES) {
NeighborForExtendedIs extendedIs = new NeighborForExtendedIs();
extendedIs.readFrom(channelBuffer);
this.addNeighbor(extendedIs);
}
}
......@@ -128,12 +75,8 @@ public class IsExtendedReachability extends TlvHeader implements IsisTlv {
*/
private byte[] tlvBodyAsBytes() {
List<Byte> byteList = new ArrayList<>();
byteList.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId()));
byteList.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.metric())));
if (this.trafEnginSubTlv.size() > 0) {
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) {
byteList.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
for (NeighborForExtendedIs neighbor : this.neighbors) {
byteList.addAll(Bytes.asList(neighbor.neighborBodyAsbytes()));
}
return Bytes.toArray(byteList);
}
......@@ -142,10 +85,7 @@ public class IsExtendedReachability extends TlvHeader implements IsisTlv {
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("neighborId", neighborId)
.add("metric", metric)
.add("trafEnginSubTlv", trafEnginSubTlv)
.add("neighbors", neighbors)
.toString();
}
}
}
\ No newline at end of file
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes;
import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvType;
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 IS extended reachability neighbors.
*/
public class NeighborForExtendedIs {
private String neighborId;
private int metric;
private List<TrafficEngineeringSubTlv> teSubTlv = new ArrayList<>();
/**
* Returns neighbor ID.
*
* @return neighbor ID
*/
public String neighborId() {
return neighborId;
}
/**
* Sets neighbor ID.
*
* @param neighborId neighbor ID
*/
public void setNeighborId(String neighborId) {
this.neighborId = neighborId;
}
/**
* Returns metric.
*
* @return metric
*/
public int metric() {
return metric;
}
/**
* Sets metric.
*
* @param metric metric
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Adds the TE for extended IS instance to IS extended reachability TLV.
*
* @param trafficEngineeringSubTlv TE for extended IS instance
*/
public void addSubTlv(TrafficEngineeringSubTlv trafficEngineeringSubTlv) {
this.teSubTlv.add(trafficEngineeringSubTlv);
}
/**
* Reads from the channel buffer and populate this instance.
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setNeighborId(IsisUtil.systemIdPlus(tempByteArray));
this.setMetric(channelBuffer.readUnsignedMedium());
int nTlvPresent = channelBuffer.readByte();
if (nTlvPresent > 0) {
while (channelBuffer.readableBytes() > IsisUtil.TWO_BYTES) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readByte());
tlvHeader.setTlvLength(channelBuffer.readByte());
SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType());
int tlvLength = tlvHeader.tlvLength();
if (tlvValue != null) {
if (channelBuffer.readableBytes() >= tlvLength) {
this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader,
channelBuffer.readBytes(tlvHeader.tlvLength())));
}
} else {
if (channelBuffer.readableBytes() >= tlvLength) {
channelBuffer.readBytes(tlvLength);
}
}
}
}
}
/**
* Returns neighbor details of IS extended reachability TLV.
*
* @return neighbor details of IS extended reachability TLV.
*/
public byte[] neighborBodyAsbytes() {
List<Byte> byteList = new ArrayList<>();
byteList.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId()));
byteList.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.metric())));
if (this.teSubTlv.size() > 0) {
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.teSubTlv) {
byteList.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
}
return Bytes.toArray(byteList);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("neighborId", neighborId)
.add("metric", metric)
.add("teSubTlv", teSubTlv)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.util.IsisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of interface ip address TE value.
*/
public class InterfaceIpAddress extends TlvHeader implements TrafficEngineeringSubTlv {
private static final Logger log =
LoggerFactory.getLogger(InterfaceIpAddress.class);
private List<Ip4Address> localInterfaceIPAddress = new ArrayList<>();
/**
* Creates an instance of local interface ip address.
*
* @param header tlv header instance
*/
public InterfaceIpAddress(TlvHeader header) {
this.setTlvType(header.tlvType());
this.setTlvLength(header.tlvLength());
}
/**
* Adds local interface ip address.
*
* @param localAddress ip address
*/
public void addLocalInterfaceIPAddress(Ip4Address localAddress) {
localInterfaceIPAddress.add(localAddress);
}
/**
* Returns local interface ip address.
*
* @return localAddress ip address
*/
public List<Ip4Address> getLocalInterfaceIPAddress() {
return localInterfaceIPAddress;
}
/**
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
while (channelBuffer.readableBytes() >= IsisUtil.FOUR_BYTES) {
byte[] tempByteArray = new byte[IsisUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES);
this.addLocalInterfaceIPAddress(Ip4Address.valueOf(tempByteArray));
}
}
/**
* Returns local interface ip address as byte array.
*
* @return local interface ip address as byte array
*/
public byte[] asBytes() {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = tlvHeaderAsByteArray();
byte[] linkSubTlvBody = tlvBodyAsBytes();
linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
return linkSubType;
}
/**
* Returns byte array of local interface ip address.
*
* @return byte array of local interface ip address
*/
public byte[] tlvBodyAsBytes() {
List<Byte> linkSubTypeBody = new ArrayList<>();
for (Ip4Address remoteAddress : this.localInterfaceIPAddress) {
linkSubTypeBody.addAll(Bytes.asList(remoteAddress.toOctets()));
}
return Bytes.toArray(linkSubTypeBody);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("localInterfaceIPAddress", localInterfaceIPAddress)
.toString();
}
}
......@@ -66,6 +66,11 @@ public final class SubTlvFinder {
unreservedBandwidth.readFrom(channelBuffer);
subTlv = unreservedBandwidth;
break;
case INTERFACEADDRESS:
InterfaceIpAddress ipInterfaceAddressTlv = new InterfaceIpAddress(tlvHeader);
ipInterfaceAddressTlv.readFrom(channelBuffer);
subTlv = ipInterfaceAddressTlv;
break;
default:
//TODO
break;
......
......@@ -60,6 +60,9 @@ public final class SubTlvToBytes {
} else if (subTlv instanceof UnreservedBandwidth) {
UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) subTlv;
subTlvBytes.addAll(Bytes.asList(unreservedBandwidth.asBytes()));
} else if (subTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress interfaceIpAddress = (InterfaceIpAddress) subTlv;
subTlvBytes.addAll(Bytes.asList(interfaceIpAddress.asBytes()));
} else {
log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes ");
}
......
......@@ -23,11 +23,30 @@ import java.util.Map;
* Representation of sub tlv type.
*/
public enum SubTlvType {
ADMINISTRATIVEGROUP(9),
MAXIMUMBANDWIDTH(6),
MAXIMUMRESERVABLEBANDWIDTH(7),
TRAFFICENGINEERINGMETRIC(5),
UNRESERVEDBANDWIDTH(8);
/**
* Represents traffic engineering administrative group TLV.
*/
ADMINISTRATIVEGROUP(3),
/**
* Represents traffic engineering maximum bandwidth TLV.
*/
MAXIMUMBANDWIDTH(9),
/**
* Represents traffic engineering maximum reservable bandwidth TLV.
*/
MAXIMUMRESERVABLEBANDWIDTH(10),
/**
* Represents traffic engineering metric TLV.
*/
TRAFFICENGINEERINGMETRIC(18),
/**
* Represents traffic engineering interface address TLV.
*/
INTERFACEADDRESS(6),
/**
* Represents traffic engineering unreserved bandwidth TLV.
*/
UNRESERVEDBANDWIDTH(11);
// Reverse lookup table
private static final Map<Integer, SubTlvType> LOOKUP = new HashMap<>();
......
/*
* 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 org.easymock.EasyMock;
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 static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for AdjacencyStateTlv.
*/
public class AdjacencyStateTlvTest {
private final String neighborSystemId = "2929.2929.2929";
private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private AdjacencyStateTlv adjacencyStateTlv;
private TlvHeader tlvHeader;
private int result;
private byte result2;
private String result1;
private ChannelBuffer channelBuffer;
private byte[] result3;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
adjacencyStateTlv = null;
channelBuffer = null;
}
/**
* Tests localCircuitId() getter method.
*/
@Test
public void testLocalCircuitId() throws Exception {
adjacencyStateTlv.setLocalCircuitId(1);
result = adjacencyStateTlv.localCircuitId();
assertThat(result, is(1));
}
/**
* Tests localCircuitId() setter method.
*/
@Test
public void testSetLocalCircuitId() throws Exception {
adjacencyStateTlv.setLocalCircuitId(1);
result = adjacencyStateTlv.localCircuitId();
assertThat(result, is(1));
}
/**
* Tests neighborSystemId() getter method.
*/
@Test
public void testNeighborSystemId() throws Exception {
adjacencyStateTlv.setNeighborSystemId(neighborSystemId);
result1 = adjacencyStateTlv.neighborSystemId();
assertThat(result1, is(neighborSystemId));
}
/**
* Tests neighborSystemId() setter method.
*/
@Test
public void testSetNeighborSystemId() throws Exception {
adjacencyStateTlv.setNeighborSystemId(neighborSystemId);
result1 = adjacencyStateTlv.neighborSystemId();
assertThat(result1, is(neighborSystemId));
}
/**
* Tests neighborLocalCircuitId() getter method.
*/
@Test
public void testNeighborLocalCircuitId() throws Exception {
adjacencyStateTlv.setNeighborLocalCircuitId(1);
result = adjacencyStateTlv.neighborLocalCircuitId();
assertThat(result, is(1));
}
/**
* Tests neighborLocalCircuitId() setter method.
*/
@Test
public void testSetNeighborLocalCircuitId() throws Exception {
adjacencyStateTlv.setNeighborLocalCircuitId(1);
result = adjacencyStateTlv.neighborLocalCircuitId();
assertThat(result, is(1));
}
/**
* Tests adjacencyType() getter method.
*/
@Test
public void testAdjacencyType() throws Exception {
adjacencyStateTlv.setAdjacencyType((byte) 1);
result2 = adjacencyStateTlv.adjacencyType();
assertThat(result2, is((byte) 1));
}
/**
* Tests adjacencyType() setter method.
*/
@Test
public void testSetAdjacencyType() throws Exception {
adjacencyStateTlv.setAdjacencyType((byte) 1);
result2 = adjacencyStateTlv.adjacencyType();
assertThat(result2, is((byte) 1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
adjacencyStateTlv.readFrom(channelBuffer);
assertThat(adjacencyStateTlv.adjacencyType(), is((byte) 0));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
adjacencyStateTlv.readFrom(channelBuffer);
result3 = adjacencyStateTlv.asBytes();
assertThat(result3, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(adjacencyStateTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for AreaAddressTlv.
*/
public class AreaAddressTlvTest {
private final String areaAddres = "490001";
private final byte[] tlv = {1, 49};
private AreaAddressTlv areaAddressTlv;
private TlvHeader tlvHeader;
private List<String> result;
private ChannelBuffer channelBuffer;
private byte[] result1;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
areaAddressTlv = new AreaAddressTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
areaAddressTlv = null;
}
/**
* Tests addAddress() method.
*/
@Test
public void testAddAddress() throws Exception {
areaAddressTlv.addAddress(areaAddres);
result = areaAddressTlv.areaAddress();
assertThat(result.size(), is(1));
}
/**
* Tests areaAddress() setter method.
*/
@Test
public void testSetAreaAddress() throws Exception {
areaAddressTlv.addAddress(areaAddres);
result = areaAddressTlv.areaAddress();
assertThat(result.size(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
areaAddressTlv.readFrom(channelBuffer);
assertThat(areaAddressTlv.areaAddress().size(), is(1));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
areaAddressTlv.readFrom(channelBuffer);
result1 = areaAddressTlv.asBytes();
assertThat(result1, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(areaAddressTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for HostNameTlv.
*/
public class HostNameTlvTest {
private final String hostName = "TEST";
private final byte[] tlv = hostName.getBytes();
private HostNameTlv hostNameTlv;
private TlvHeader tlvHeader;
private String result;
private ChannelBuffer channelBuffer;
private byte[] result1;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(tlv.length);
hostNameTlv = new HostNameTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
hostNameTlv = null;
}
/**
* Tests hostName() getter method.
*/
@Test
public void testHostName() throws Exception {
hostNameTlv.setHostName(hostName);
result = hostNameTlv.hostName();
assertThat(result, is(hostName));
}
/**
* Tests hostName() setter method.
*/
@Test
public void testSetHostName() throws Exception {
hostNameTlv.setHostName(hostName);
result = hostNameTlv.hostName();
assertThat(result, is(hostName));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
hostNameTlv.readFrom(channelBuffer);
assertThat(hostNameTlv.hostName(), is(hostName));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
hostNameTlv.readFrom(channelBuffer);
result1 = hostNameTlv.asBytes();
assertThat(result1, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(hostNameTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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.isis.io.isispacket.tlv.subtlv.AdministrativeGroup;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IP ExtendedReachabilityTlv.
*/
public class IpExtendedReachabilityTlvTest {
private final String prefix = "00";
private final byte[] tlv = {0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0};
private final byte[] tlv1 = {0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0};
private final byte[] tlv2 = {0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0};
private final byte[] tlv3 = {0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0};
private TlvHeader tlvHeader;
private IpExtendedReachabilityTlv ipExtendedReachabilityTlv;
private String result;
private boolean result1;
private int result2;
private TrafficEngineeringSubTlv trafficEngineeringSubTlv;
private byte result4;
private ChannelBuffer channelBuffer;
private byte[] result3;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
ipExtendedReachabilityTlv = new IpExtendedReachabilityTlv(tlvHeader);
trafficEngineeringSubTlv = new AdministrativeGroup(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
ipExtendedReachabilityTlv = null;
}
/**
* Tests prefix() getter method.
*/
@Test
public void testPrefix() throws Exception {
ipExtendedReachabilityTlv.setPrefix(prefix);
result = ipExtendedReachabilityTlv.prefix();
assertThat(result, is("00"));
}
/**
* Tests prefix() setter method.
*/
@Test
public void testSetPrefix() throws Exception {
ipExtendedReachabilityTlv.setPrefix(prefix);
result = ipExtendedReachabilityTlv.prefix();
assertThat(result, is("00"));
}
/**
* Tests isDown() getter method.
*/
@Test
public void testIsDown() throws Exception {
ipExtendedReachabilityTlv.setDown(true);
result1 = ipExtendedReachabilityTlv.isDown();
assertThat(result1, is(true));
}
/**
* Tests isDown() setter method.
*/
@Test
public void testSetDown() throws Exception {
ipExtendedReachabilityTlv.setDown(true);
result1 = ipExtendedReachabilityTlv.isDown();
assertThat(result1, is(true));
}
/**
* Tests isSubTlvPresence() getter method.
*/
@Test
public void testIsSubTlvPresence() throws Exception {
ipExtendedReachabilityTlv.setSubTlvPresence(true);
result1 = ipExtendedReachabilityTlv.isSubTlvPresence();
assertThat(result1, is(true));
}
/**
* Tests isSubTlvPresence() setter method.
*/
@Test
public void testSetSubTlvPresence() throws Exception {
ipExtendedReachabilityTlv.setSubTlvPresence(true);
result1 = ipExtendedReachabilityTlv.isSubTlvPresence();
assertThat(result1, is(true));
}
/**
* Tests prefixLength() getter method.
*/
@Test
public void testPrefixLength() throws Exception {
ipExtendedReachabilityTlv.setPrefixLength(10);
result2 = ipExtendedReachabilityTlv.prefixLength();
assertThat(result2, is(10));
}
/**
* Tests prefixLength() setter method.
*/
@Test
public void testSetPrefixLength() throws Exception {
ipExtendedReachabilityTlv.setPrefixLength(10);
result2 = ipExtendedReachabilityTlv.prefixLength();
assertThat(result2, is(10));
}
/**
* Tests addNeighbor() method.
*/
@Test
public void testAddSubTlv() throws Exception {
ipExtendedReachabilityTlv.addSubTlv(trafficEngineeringSubTlv);
assertThat(ipExtendedReachabilityTlv, is(notNullValue()));
}
/**
* Tests subTlvLength() getter method.
*/
@Test
public void testSubTlvLength() throws Exception {
ipExtendedReachabilityTlv.setSubTlvLength((byte) 10);
result4 = ipExtendedReachabilityTlv.subTlvLength();
assertThat(result4, is((byte) 10));
}
/**
* Tests subTlvLength() setter method.
*/
@Test
public void testSetSubTlvLength() throws Exception {
ipExtendedReachabilityTlv.setSubTlvLength((byte) 10);
result4 = ipExtendedReachabilityTlv.subTlvLength();
assertThat(result4, is((byte) 10));
}
/**
* Tests metric() getter method.
*/
@Test
public void testMetric() throws Exception {
ipExtendedReachabilityTlv.setMetric(10);
result2 = ipExtendedReachabilityTlv.metric();
assertThat(result2, is(10));
}
/**
* Tests metric() setter method.
*/
@Test
public void testSetMetric() throws Exception {
ipExtendedReachabilityTlv.setMetric(10);
result2 = ipExtendedReachabilityTlv.metric();
assertThat(result2, is(10));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipExtendedReachabilityTlv.readFrom(channelBuffer);
assertThat(ipExtendedReachabilityTlv.metric(), is(0));
channelBuffer = ChannelBuffers.copiedBuffer(tlv1);
ipExtendedReachabilityTlv.readFrom(channelBuffer);
assertThat(ipExtendedReachabilityTlv.metric(), is(0));
channelBuffer = ChannelBuffers.copiedBuffer(tlv2);
ipExtendedReachabilityTlv.readFrom(channelBuffer);
assertThat(ipExtendedReachabilityTlv.metric(), is(0));
channelBuffer = ChannelBuffers.copiedBuffer(tlv3);
ipExtendedReachabilityTlv.readFrom(channelBuffer);
assertThat(ipExtendedReachabilityTlv.metric(), is(0));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipExtendedReachabilityTlv.readFrom(channelBuffer);
ipExtendedReachabilityTlv.setPrefix(prefix);
result3 = ipExtendedReachabilityTlv.asBytes();
assertThat(result3, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(ipExtendedReachabilityTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IP InterfaceAddressTlv.
*/
public class IpInterfaceAddressTlvTest {
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
private final byte[] tlv = {0, 0, 0, 0};
private TlvHeader tlvHeader;
private IpInterfaceAddressTlv ipInterfaceAddressTlv;
private List<Ip4Address> resultList;
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
ipInterfaceAddressTlv = null;
}
/**
* Tests addInterfaceAddress() method.
*/
@Test
public void testAddInterfaceAddres() throws Exception {
ipInterfaceAddressTlv.addInterfaceAddres(ip4Address);
resultList = ipInterfaceAddressTlv.interfaceAddress();
assertThat(resultList.size(), is(1));
}
/**
* Tests interfaceAddress() getter method.
*/
@Test
public void testInterfaceAddress() throws Exception {
ipInterfaceAddressTlv.addInterfaceAddres(ip4Address);
resultList = ipInterfaceAddressTlv.interfaceAddress();
assertThat(resultList.size(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipInterfaceAddressTlv.readFrom(channelBuffer);
assertThat(ipInterfaceAddressTlv.interfaceAddress().size(), is(1));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipInterfaceAddressTlv.readFrom(channelBuffer);
result = ipInterfaceAddressTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(ipInterfaceAddressTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IP InternalReachabilityTlv.
*/
public class IpInternalReachabilityTlvTest {
private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private TlvHeader tlvHeader;
private IpInternalReachabilityTlv ipInternalReachabilityTlv;
private MetricOfInternalReachability metricOfInternalReachability;
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
ipInternalReachabilityTlv = new IpInternalReachabilityTlv(tlvHeader);
metricOfInternalReachability = new MetricOfInternalReachability();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
ipInternalReachabilityTlv = null;
}
/**
* Tests addInternalReachabilityMetric() method.
*/
@Test
public void testAddInternalReachabilityMetric() throws Exception {
ipInternalReachabilityTlv.addInternalReachabilityMetric(metricOfInternalReachability);
assertThat(ipInternalReachabilityTlv, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipInternalReachabilityTlv.readFrom(channelBuffer);
assertThat(ipInternalReachabilityTlv, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
ipInternalReachabilityTlv.readFrom(channelBuffer);
result = ipInternalReachabilityTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(ipInternalReachabilityTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IS ReachabilityTlv.
*/
public class IsReachabilityTlvTest {
private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private TlvHeader tlvHeader;
private IsReachabilityTlv isReachabilityTlv;
private MetricsOfReachability metricsOfReachability;
private int resultInt;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
isReachabilityTlv = new IsReachabilityTlv(tlvHeader);
metricsOfReachability = new MetricsOfReachability();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
isReachabilityTlv = null;
}
/**
* Tests reserved() getter method.
*/
@Test
public void testReserved() throws Exception {
isReachabilityTlv.setReserved(10);
resultInt = isReachabilityTlv.reserved();
assertThat(resultInt, is(10));
}
/**
* Tests reserved() setter method.
*/
@Test
public void testSetReserved() throws Exception {
isReachabilityTlv.setReserved(10);
resultInt = isReachabilityTlv.reserved();
assertThat(resultInt, is(10));
}
/**
* Tests addMeticsOfReachability() getter method.
*/
@Test
public void testAddMeticsOfReachability() throws Exception {
isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
assertThat(isReachabilityTlv, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
isReachabilityTlv.readFrom(channelBuffer);
assertThat(isReachabilityTlv, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
isReachabilityTlv.readFrom(channelBuffer);
result = isReachabilityTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(isReachabilityTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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.MacAddress;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for ISIS NeighborTLV.
*/
public class IsisNeighborTlvTest {
private final MacAddress macAddress = MacAddress.valueOf("a4:23:05:00:00:00");
private final byte[] tlv = {0, 0, 0, 0, 0, 0};
private TlvHeader tlvHeader;
private IsisNeighborTlv isisNeighborTlv;
private List<MacAddress> resultList;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
isisNeighborTlv = null;
}
/**
* Tests addNeighbor() getter method.
*/
@Test
public void testAddNeighbor() throws Exception {
isisNeighborTlv.addNeighbor(macAddress);
resultList = isisNeighborTlv.neighbor();
assertThat(resultList.size(), is(1));
}
/**
* Tests neighbor() setter method.
*/
@Test
public void testNeighbor() throws Exception {
isisNeighborTlv.addNeighbor(macAddress);
resultList = isisNeighborTlv.neighbor();
assertThat(resultList.size(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
isisNeighborTlv.readFrom(channelBuffer);
assertThat(isisNeighborTlv.neighbor().size(), is(1));
}
/**
* Tests asBytes() getter method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
isisNeighborTlv.readFrom(channelBuffer);
result = isisNeighborTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(isisNeighborTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for LspEntriesTlv.
*/
public class LspEntriesTlvTest {
private final byte[] entry = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private LspEntriesTlv lspEntriesTlv;
private TlvHeader tlvHeader;
private List<LspEntry> lspEntries = new ArrayList();
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
lspEntriesTlv = new LspEntriesTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
lspEntriesTlv = null;
lspEntries.clear();
}
/**
* Tests lspEntry() getter method.
*/
@Test
public void testLspEntry() throws Exception {
lspEntriesTlv.addLspEntry(new LspEntry());
assertThat(lspEntriesTlv.lspEntry().size(), is(1));
}
/**
* Tests lspEntry() add method.
*/
@Test
public void testAddLspEntry() throws Exception {
lspEntriesTlv.addLspEntry(new LspEntry());
assertThat(lspEntriesTlv.lspEntry().size(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(entry);
lspEntriesTlv.readFrom(channelBuffer);
lspEntries = lspEntriesTlv.lspEntry();
assertThat(lspEntriesTlv.lspEntry().size(), is(1));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(entry);
lspEntriesTlv.readFrom(channelBuffer);
lspEntriesTlv.asBytes();
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(lspEntriesTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for LspEntry.
*/
public class LspEntryTest {
private final String lspId = "10.10.10.10";
private final byte[] entry = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private LspEntry lspEntry;
private int result;
private String result2;
private ChannelBuffer channelBuffer;
private byte[] result3;
@Before
public void setUp() throws Exception {
lspEntry = new LspEntry();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
lspEntry = null;
channelBuffer = null;
}
/**
* Tests lspSequenceNumber() getter method.
*/
@Test
public void testLspSequenceNumber() throws Exception {
lspEntry.setLspSequenceNumber(0);
result = lspEntry.lspSequenceNumber();
assertThat(result, is(0));
}
/**
* Tests lspSequenceNumber() setter method.
*/
@Test
public void testSetLspSequenceNumber() throws Exception {
lspEntry.setLspSequenceNumber(0);
result = lspEntry.lspSequenceNumber();
assertThat(result, is(0));
}
/**
* Tests lspChecksum() getter method.
*/
@Test
public void testLspChecksum() throws Exception {
lspEntry.setLspChecksum(0);
result = lspEntry.lspChecksum();
assertThat(result, is(0));
}
/**
* Tests lspChecksum() setter method.
*/
@Test
public void testSetLspChecksum() throws Exception {
lspEntry.setLspChecksum(0);
result = lspEntry.lspChecksum();
assertThat(result, is(0));
}
/**
* Tests remainingTime() getter method.
*/
@Test
public void testRemainingTime() throws Exception {
lspEntry.setRemainingTime(0);
result = lspEntry.remainingTime();
assertThat(result, is(0));
}
/**
* Tests remainingTime() setter method.
*/
@Test
public void testSetRemainingTime() throws Exception {
lspEntry.setRemainingTime(0);
result = lspEntry.remainingTime();
assertThat(result, is(0));
}
/**
* Tests lspId() getter method.
*/
@Test
public void testLspId() throws Exception {
lspEntry.setLspId(lspId);
result2 = lspEntry.lspId();
assertThat(result2, is("10.10.10.10"));
}
/**
* Tests lspId() getter method.
*/
@Test
public void testSetLspId() throws Exception {
lspEntry.setLspId(lspId);
result2 = lspEntry.lspId();
assertThat(result2, is("10.10.10.10"));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(entry);
lspEntry.readFrom(channelBuffer);
assertThat(lspEntry, is(notNullValue()));
}
/**
* Tests lspEntryAsBytes() method.
*/
@Test
public void testLspEntryAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(entry);
lspEntry.readFrom(channelBuffer);
result3 = lspEntry.lspEntryAsBytes();
assertThat(lspEntry, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(lspEntry.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for MetricOfInternalReachability.
*/
public class MetricOfInternalReachabilityTest {
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
private final byte[] internalReachability = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private MetricOfInternalReachability reachability;
private Ip4Address result;
private boolean result1;
private byte result2;
private ChannelBuffer channelBuffer;
private byte[] result3;
@Before
public void setUp() throws Exception {
reachability = new MetricOfInternalReachability();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
reachability = null;
result = null;
result1 = false;
}
/**
* Tests getIpAddress() getter method.
*/
@Test
public void testGetIpAddress() throws Exception {
reachability.setIpAddress(ip4Address);
result = reachability.getIpAddress();
assertThat(result, is(ip4Address));
}
/**
* Tests setIpAddress() setter method.
*/
@Test
public void testSetIpAddress() throws Exception {
reachability.setIpAddress(ip4Address);
result = reachability.getIpAddress();
assertThat(result, is(ip4Address));
}
/**
* Tests getSubnetAddres() getter method.
*/
@Test
public void testGetSubnetAddres() throws Exception {
reachability.setSubnetAddres(ip4Address);
result = reachability.getSubnetAddres();
assertThat(result, is(ip4Address));
}
/**
* Tests setSubnetAddres() setter method.
*/
@Test
public void testSetSubnetAddres() throws Exception {
reachability.setSubnetAddres(ip4Address);
result = reachability.getSubnetAddres();
assertThat(result, is(ip4Address));
}
/**
* Tests isErrorIsInternal() getter method.
*/
@Test
public void testIsErrorIsInternal() throws Exception {
reachability.setErrorIsInternal(true);
result1 = reachability.isErrorIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isErrorIsInternal() setter method.
*/
@Test
public void testSetErrorIsInternal() throws Exception {
reachability.setErrorIsInternal(true);
result1 = reachability.isErrorIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isExpenseIsInternal() getter method.
*/
@Test
public void testIsExpenseIsInternal() throws Exception {
reachability.setExpenseIsInternal(true);
result1 = reachability.isExpenseIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isExpenseIsInternal() setter method.
*/
@Test
public void testSetExpenseIsInternal() throws Exception {
reachability.setExpenseIsInternal(true);
result1 = reachability.isExpenseIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDelayIsInternal() getter method.
*/
@Test
public void testIsDelayIsInternal() throws Exception {
reachability.setDelayIsInternal(true);
result1 = reachability.isDelayIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDelayIsInternal() setter method.
*/
@Test
public void testSetDelayIsInternal() throws Exception {
reachability.setDelayIsInternal(true);
result1 = reachability.isDelayIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDefaultDistributionDown() getter method.
*/
@Test
public void testIsDefaultDistributionDown() throws Exception {
reachability.setDefaultDistributionDown(true);
result1 = reachability.isDefaultDistributionDown();
assertThat(result1, is(true));
}
/**
* Tests isDefaultDistributionDown() setter method.
*/
@Test
public void testSetDefaultDistributionDown() throws Exception {
reachability.setDefaultDistributionDown(true);
result1 = reachability.isDefaultDistributionDown();
assertThat(result1, is(true));
}
/**
* Tests isDefaultIsInternal() getter method.
*/
@Test
public void testIsDefaultIsInternal() throws Exception {
reachability.setDefaultIsInternal(true);
result1 = reachability.isDefaultIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDefaultIsInternal() setter method.
*/
@Test
public void testSetDefaultIsInternal() throws Exception {
reachability.setDefaultIsInternal(true);
result1 = reachability.isDefaultIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isErrorMetricSupported() getter method.
*/
@Test
public void testIsErrorMetricSupported() throws Exception {
reachability.setErrorMetricSupported(true);
result1 = reachability.isErrorMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isErrorMetricSupported() setter method.
*/
@Test
public void testSetErrorMetricSupported() throws Exception {
reachability.setErrorMetricSupported(true);
result1 = reachability.isErrorMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isExpenseMetricSupported() setter method.
*/
@Test
public void testIsExpenseMetricSupported() throws Exception {
reachability.setExpenseMetricSupported(true);
result1 = reachability.isExpenseMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isExpenseMetricSupported() setter method.
*/
@Test
public void testSetExpenseMetricSupported() throws Exception {
reachability.setExpenseMetricSupported(true);
result1 = reachability.isExpenseMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isDelayMetricSupported() getter method.
*/
@Test
public void testIsDelayMetricSupported() throws Exception {
reachability.setDelayMetricSupported(true);
result1 = reachability.isDelayMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isDelayMetricSupported() setter method.
*/
@Test
public void testSetDelayMetricSupported() throws Exception {
reachability.setDelayMetricSupported(true);
result1 = reachability.isDelayMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests errorMetric() getter method.
*/
@Test
public void testErrorMetric() throws Exception {
reachability.setErrorMetric((byte) 0);
result2 = reachability.errorMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests errorMetric() setter method.
*/
@Test
public void testSetErrorMetric() throws Exception {
reachability.setErrorMetric((byte) 0);
result2 = reachability.errorMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests delayMetric() getter method.
*/
@Test
public void testDelayMetric() throws Exception {
reachability.setDelayMetric((byte) 0);
result2 = reachability.delayMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests delayMetric() setter method.
*/
@Test
public void testSetDelayMetric() throws Exception {
reachability.setDelayMetric((byte) 0);
result2 = reachability.delayMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests defaultMetric() getter method.
*/
@Test
public void testDefaultMetric() throws Exception {
reachability.setDefaultMetric((byte) 0);
result2 = reachability.defaultMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests defaultMetric() setter method.
*/
@Test
public void testSetDefaultMetric() throws Exception {
reachability.setDefaultMetric((byte) 0);
result2 = reachability.defaultMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(internalReachability);
reachability.readFrom(channelBuffer);
assertThat(reachability, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(internalReachability);
reachability.readFrom(channelBuffer);
result3 = reachability.asBytes();
assertThat(result3, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(reachability.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
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 static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for MetricsOfReachability.
*/
public class MetricsOfReachabilityTest {
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
private final byte[] metricReachability = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private MetricsOfReachability reachability;
private String neighborId = "2929.2929.2929";
private Ip4Address result;
private boolean result1;
private byte result2;
private ChannelBuffer channelBuffer;
private byte[] result3;
private String result4;
@Before
public void setUp() throws Exception {
reachability = new MetricsOfReachability();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
result1 = false;
}
@After
public void tearDown() throws Exception {
reachability = null;
result1 = false;
result3 = null;
channelBuffer = null;
}
/**
* Tests isDelayIsInternal() getter method.
*/
@Test
public void testIsDelayIsInternal() throws Exception {
reachability.setDelayIsInternal(true);
result1 = reachability.isDelayIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDelayIsInternal() setter method.
*/
@Test
public void testSetDelayIsInternal() throws Exception {
reachability.setDelayIsInternal(true);
result1 = reachability.isDelayIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isExpenseIsInternal() getter method.
*/
@Test
public void testIsExpenseIsInternal() throws Exception {
reachability.setExpenseIsInternal(true);
result1 = reachability.isExpenseIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isExpenseIsInternal() setter method.
*/
@Test
public void testSetExpenseIsInternal() throws Exception {
reachability.setExpenseIsInternal(true);
result1 = reachability.isExpenseIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isErrorIsInternal() getter method.
*/
@Test
public void testIsErrorIsInternal() throws Exception {
reachability.setErrorIsInternal(true);
result1 = reachability.isErrorIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isErrorIsInternal() setter method.
*/
@Test
public void testSetErrorIsInternal() throws Exception {
reachability.setErrorIsInternal(true);
result1 = reachability.isErrorIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDefaultIsInternal() getter method.
*/
@Test
public void testIsDefaultIsInternal() throws Exception {
reachability.setDefaultIsInternal(true);
result1 = reachability.isDefaultIsInternal();
assertThat(result1, is(true));
}
/**
* Tests isDefaultIsInternal() setter method.
*/
@Test
public void testSetDefaultIsInternal() throws Exception {
reachability.setDefaultIsInternal(true);
result1 = reachability.isDefaultIsInternal();
assertThat(result1, is(true));
}
@Test
public void testIsDelayMetricSupported() throws Exception {
reachability.setDelayMetricSupported(true);
result1 = reachability.isDelayMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isDelayMetricSupported() setter method.
*/
@Test
public void testSetDelayMetricSupported() throws Exception {
reachability.setDelayMetricSupported(true);
result1 = reachability.isDelayMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isExpenseMetricSupported() getter method.
*/
@Test
public void testIsExpenseMetricSupported() throws Exception {
reachability.setExpenseMetricSupported(true);
result1 = reachability.isExpenseMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isExpenseMetricSupported() setter method.
*/
@Test
public void testSetExpenseMetricSupported() throws Exception {
reachability.setExpenseMetricSupported(true);
result1 = reachability.isExpenseMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isErrorMetricSupported() getter method.
*/
@Test
public void testIsErrorMetricSupported() throws Exception {
reachability.setErrorMetricSupported(true);
result1 = reachability.isErrorMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests isErrorMetricSupported() setter method.
*/
@Test
public void testSetErrorMetricSupported() throws Exception {
reachability.setErrorMetricSupported(true);
result1 = reachability.isErrorMetricSupported();
assertThat(result1, is(true));
}
/**
* Tests neighborId() getter method.
*/
@Test
public void testNeighborId() throws Exception {
reachability.setNeighborId(neighborId);
result4 = reachability.neighborId();
assertThat(result4, is(neighborId));
}
/**
* Tests neighborId() setter method.
*/
@Test
public void testSetNeighborId() throws Exception {
reachability.setNeighborId(neighborId);
result4 = reachability.neighborId();
assertThat(result4, is(neighborId));
}
/**
* Tests defaultMetric() getter method.
*/
@Test
public void testDefaultMetric() throws Exception {
reachability.setDefaultMetric((byte) 0);
result2 = reachability.defaultMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests defaultMetric() setter method.
*/
@Test
public void testSetDefaultMetric() throws Exception {
reachability.setDefaultMetric((byte) 0);
result2 = reachability.defaultMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests delayMetric() getter method.
*/
@Test
public void testDelayMetric() throws Exception {
reachability.setDelayMetric((byte) 0);
result2 = reachability.delayMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests delayMetric() setter method.
*/
@Test
public void testSetDelayMetric() throws Exception {
reachability.setDelayMetric((byte) 0);
result2 = reachability.delayMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests expenseMetric() getter method.
*/
@Test
public void testExpenseMetric() throws Exception {
reachability.setExpenseMetric((byte) 0);
result2 = reachability.expenseMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests expenseMetric() setter method.
*/
@Test
public void testSetExpenseMetric() throws Exception {
reachability.setExpenseMetric((byte) 0);
result2 = reachability.expenseMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests errorMetric() getter method.
*/
@Test
public void testErrorMetric() throws Exception {
reachability.setErrorMetric((byte) 0);
result2 = reachability.errorMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests errorMetric() setter method.
*/
@Test
public void testSetErrorMetric() throws Exception {
reachability.setErrorMetric((byte) 0);
result2 = reachability.errorMetric();
assertThat(result2, is((byte) 0));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(metricReachability);
reachability.readFrom(channelBuffer);
assertThat(reachability, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(metricReachability);
reachability.readFrom(channelBuffer);
result3 = reachability.asBytes();
assertThat(result3, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(reachability.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for PaddingTlv.
*/
public class PaddingTlvTest {
private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0};
private PaddingTlv paddingTlv;
private TlvHeader tlvHeader;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
paddingTlv = new PaddingTlv(tlvHeader);
}
@After
public void tearDown() throws Exception {
paddingTlv = null;
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
paddingTlv.readFrom(channelBuffer);
assertThat(paddingTlv, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
paddingTlv.readFrom(channelBuffer);
result = paddingTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() getter method.
*/
@Test
public void testToString() throws Exception {
assertThat(paddingTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for ProtocolSupportedTlv.
*/
public class ProtocolSupportedTlvTest {
private final byte[] tlv = {0};
private ProtocolSupportedTlv protocolSupportedTlv;
private TlvHeader tlvHeader;
private List<Byte> supported;
private ChannelBuffer channelBuffer;
private byte[] result;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
protocolSupportedTlv = null;
channelBuffer = null;
}
/**
* Tests addProtocolSupported() method.
*/
@Test
public void testAddProtocolSupported() throws Exception {
protocolSupportedTlv.addProtocolSupported((byte) 1);
supported = protocolSupportedTlv.protocolSupported();
assertThat(supported.size(), is(1));
}
/**
* Tests addProtocolSupported() getter method.
*/
@Test
public void testProtocolSupported() throws Exception {
protocolSupportedTlv.addProtocolSupported((byte) 1);
supported = protocolSupportedTlv.protocolSupported();
assertThat(supported.size(), is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
protocolSupportedTlv.readFrom(channelBuffer);
supported = protocolSupportedTlv.protocolSupported();
assertThat(supported.size(), is(1));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
protocolSupportedTlv.readFrom(channelBuffer);
result = protocolSupportedTlv.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(protocolSupportedTlv.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
/**
* Unit test class for TlvFinder.
*/
public class TlvFinderTest {
private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private final byte[] tlv1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private TlvFinder tlvFinder;
private TlvHeader tlvHeader;
private ChannelBuffer channelBuffer;
private IsisTlv isisTlv;
@Before
public void setUp() throws Exception {
tlvFinder = new TlvFinder();
tlvHeader = new TlvHeader();
}
@After
public void tearDown() throws Exception {
tlvFinder = null;
isisTlv = null;
}
/**
* Tests IsisTlv() getter method.
*/
@Test
public void testIsisTlv() throws Exception {
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(AreaAddressTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.HOSTNAME.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(HostNameTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.IDRPINFORMATION.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IdrpInformationTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.IPEXTENDEDREACHABILITY.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IpExtendedReachabilityTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IpInterfaceAddressTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.IPINTERNALREACHABILITY.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IpInternalReachabilityTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(ProtocolSupportedTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.ISREACHABILITY.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IsReachabilityTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(IsisNeighborTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.LSPENTRY.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(LspEntriesTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv);
tlvHeader.setTlvType(TlvType.PADDING.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(PaddingTlv.class));
channelBuffer = ChannelBuffers.copiedBuffer(tlv1);
tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
isisTlv = tlvFinder.findTlv(tlvHeader, channelBuffer);
assertThat(isisTlv, instanceOf(AdjacencyStateTlv.class));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for TlvHeader.
*/
public class TlvHeaderTest {
private TlvHeader tlvHeader;
private int result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
channelBuffer = null;
}
/**
* Tests tlvLength() getter method.
*/
@Test
public void testTlvLength() throws Exception {
tlvHeader.setTlvLength(1);
result = tlvHeader.tlvLength();
assertThat(result, is(1));
}
/**
* Tests tlvLength() setter method.
*/
@Test
public void testSetTlvLength() throws Exception {
tlvHeader.setTlvLength(1);
result = tlvHeader.tlvLength();
assertThat(result, is(1));
}
/**
* Tests tlvType() getter method.
*/
@Test
public void testTlvType() throws Exception {
tlvHeader.setTlvType(1);
result = tlvHeader.tlvType();
assertThat(result, is(1));
}
/**
* Tests tlvType() setter method.
*/
@Test
public void testSetTlvType() throws Exception {
tlvHeader.setTlvType(1);
result = tlvHeader.tlvType();
assertThat(result, is(1));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
tlvHeader.readFrom(channelBuffer);
assertThat(tlvHeader, is(notNullValue()));
}
/**
* Tests asBytes() getter method.
*/
@Test
public void testAsBytes() throws Exception {
assertThat(tlvHeader.asBytes(), is(nullValue()));
}
/**
* Tests tlvHeaderAsByteArray() method.
*/
@Test
public void testTlvHeaderAsByteArray() throws Exception {
tlvHeader.setTlvLength(1);
tlvHeader.setTlvType(1);
assertThat(tlvHeader.tlvHeaderAsByteArray(), is(notNullValue()));
assertThat(tlvHeader.tlvType(), is(1));
assertThat(tlvHeader.tlvLength(), is(1));
}
/**
* Tests toString() getter method.
*/
@Test
public void testToString() throws Exception {
assertThat(tlvHeader.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.isis.controller.IsisInterfaceState;
import org.onosproject.isis.io.util.IsisConstants;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for TlvsToBytes.
*/
public class TlvsToBytesTest {
private final String areaAddress = "49";
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
private final String systemName = "ROUTER";
private final String neighborId = "2929.2929.2929";
private List<Byte> tlv;
private MacAddress macAddress = MacAddress.valueOf("a4:23:05:00:00:00");
private String prefix = "192.168.7";
/**
* Tests TlvToBytes() method.
*/
@Test
public void testTlvToBytes() throws Exception {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
tlvHeader.setTlvLength(0);
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(areaAddress);
tlv = TlvsToBytes.tlvToBytes(areaAddressTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
tlvHeader.setTlvLength(0);
ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
protocolSupportedTlv.addProtocolSupported((byte) IsisConstants.PROTOCOLSUPPORTED);
tlv = TlvsToBytes.tlvToBytes(protocolSupportedTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.IPINTERFACEADDRESS.value());
tlvHeader.setTlvLength(0);
IpInterfaceAddressTlv ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
ipInterfaceAddressTlv.addInterfaceAddres(ip4Address);
tlv = TlvsToBytes.tlvToBytes(ipInterfaceAddressTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.HOSTNAME.value());
tlvHeader.setTlvLength(0);
HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader);
hostNameTlv.setHostName(systemName);
tlv = TlvsToBytes.tlvToBytes(hostNameTlv);
assertThat(tlv, is(notNullValue()));
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);
metricsOfReachability.setNeighborId(neighborId);
isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
tlv = TlvsToBytes.tlvToBytes(isReachabilityTlv);
assertThat(tlv, is(notNullValue()));
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(ip4Address);
metricOfIntRea.setSubnetAddres(ip4Address);
ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
tlv = TlvsToBytes.tlvToBytes(ipInterReacTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.PADDING.value());
tlvHeader.setTlvLength(255);
PaddingTlv paddingTlv = new PaddingTlv(tlvHeader);
tlv = TlvsToBytes.tlvToBytes(paddingTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.IPEXTENDEDREACHABILITY.value());
tlvHeader.setTlvLength(0);
IpExtendedReachabilityTlv extendedTlv = new IpExtendedReachabilityTlv(tlvHeader);
extendedTlv.setDown(false);
extendedTlv.setMetric(10);
extendedTlv.setPrefix(prefix);
extendedTlv.setPrefixLength(24);
extendedTlv.setSubTlvLength((byte) 0);
extendedTlv.setSubTlvPresence(false);
tlv = TlvsToBytes.tlvToBytes(extendedTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
tlvHeader.setTlvLength(0);
AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value());
tlv = TlvsToBytes.tlvToBytes(adjacencyStateTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value());
tlvHeader.setTlvLength(0);
IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
isisNeighborTlv.addNeighbor(macAddress);
tlv = TlvsToBytes.tlvToBytes(isisNeighborTlv);
assertThat(tlv, is(notNullValue()));
tlvHeader.setTlvType(TlvType.EXTENDEDISREACHABILITY.value());
tlvHeader.setTlvLength(0);
IsExtendedReachability reachability = new IsExtendedReachability(tlvHeader);
NeighborForExtendedIs forExtendedIs = new NeighborForExtendedIs();
forExtendedIs.setMetric(10);
forExtendedIs.setNeighborId(neighborId);
reachability.addNeighbor(forExtendedIs);
tlv = TlvsToBytes.tlvToBytes(reachability);
assertThat(tlv, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.isispacket.tlv.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.tlvBodyAsBytes();
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-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for InterfaceIpAddress.
*/
public class InterfaceIpAddressTest {
private final byte[] packet = {1, 1, 1, 1};
private final byte[] packet1 = {};
private InterfaceIpAddress interfaceIpAddress;
private TlvHeader tlvHeader;
private Ip4Address ip4Address = Ip4Address.valueOf("1.1.1.1");
private byte[] result;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
interfaceIpAddress = new InterfaceIpAddress(new TlvHeader());
}
@After
public void tearDown() throws Exception {
interfaceIpAddress = null;
tlvHeader = null;
result = null;
channelBuffer = null;
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(interfaceIpAddress.toString(), is(notNullValue()));
}
/**
* Tests addLocalInterfaceIPAddress() method.
*/
@Test
public void testAddLocalInterfaceIPAddress() throws Exception {
interfaceIpAddress.addLocalInterfaceIPAddress(ip4Address);
assertThat(interfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(3);
tlvHeader.setTlvLength(4);
interfaceIpAddress = new InterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
interfaceIpAddress.readFrom(channelBuffer);
assertThat(interfaceIpAddress, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom1() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(3);
tlvHeader.setTlvLength(4);
interfaceIpAddress = new InterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
interfaceIpAddress.readFrom(channelBuffer);
assertThat(interfaceIpAddress, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result = interfaceIpAddress.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLinkSubTypeTlvBodyAsByteArray() method.
*/
@Test
public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
result = interfaceIpAddress.tlvBodyAsBytes();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.isispacket.tlv.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-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.isispacket.tlv.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.tlvBodyAsBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(maximumReservableBandwidth.toString(), is(notNullValue()));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.easymock.EasyMock;
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.isis.io.isispacket.tlv.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for SubTlvFinder.
*/
public class SubTlvFinderTest {
private final byte[] packet1 = {0, 0, 0, 1};
private TlvHeader tlvHeader;
private ChannelBuffer channelBuffer;
private TrafficEngineeringSubTlv tlv;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
channelBuffer = null;
}
@Test
public void testFindSubTlv() throws Exception {
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.ADMINISTRATIVEGROUP.value());
AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.TRAFFICENGINEERINGMETRIC.value());
TrafficEngineeringMetric trafficEngineeringMetric = new TrafficEngineeringMetric(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.MAXIMUMBANDWIDTH.value());
MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.MAXIMUMRESERVABLEBANDWIDTH.value());
MaximumReservableBandwidth maximumReservableBandwidth = new MaximumReservableBandwidth(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.UNRESERVEDBANDWIDTH.value());
UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(SubTlvType.INTERFACEADDRESS.value());
InterfaceIpAddress ipInterfaceAddressTlv = new InterfaceIpAddress(tlvHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet1);
tlv = SubTlvFinder.findSubTlv(tlvHeader, channelBuffer);
assertThat(tlv, is(notNullValue()));
}
}
\ No newline at end of file
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for SubTlvToBytes.
*/
public class SubTlvToBytesTest {
private TlvHeader tlvHeader;
private ChannelBuffer channelBuffer;
private List<Byte> tlv;
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
@After
public void tearDown() throws Exception {
tlvHeader = null;
channelBuffer = null;
}
@Test
public void testTlvToBytes() throws Exception {
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(9);
AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
tlv = SubTlvToBytes.tlvToBytes(administrativeGroup);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(5);
TrafficEngineeringMetric trafficEngineeringMetric = new TrafficEngineeringMetric(tlvHeader);
tlv = SubTlvToBytes.tlvToBytes(trafficEngineeringMetric);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(6);
MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
tlv = SubTlvToBytes.tlvToBytes(maximumBandwidth);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(7);
MaximumReservableBandwidth maximumReservableBandwidth = new MaximumReservableBandwidth(tlvHeader);
tlv = SubTlvToBytes.tlvToBytes(maximumReservableBandwidth);
assertThat(tlv, is(notNullValue()));
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(4);
tlvHeader.setTlvType(8);
UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
tlv = SubTlvToBytes.tlvToBytes(unreservedBandwidth);
assertThat(tlv, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
/**
* 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.tlvBodyAsBytes();
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-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.io.isispacket.tlv.subtlv;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for UnreservedBandwidth.
*/
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.asBytes();
assertThat(result, is(notNullValue()));
}
}
\ No newline at end of file