Mohamed Rahil
Committed by Gerrit Code Review

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

Change-Id: I3f09176ad4ccc330b8989f13b12f74dc86f53ae4
Showing 17 changed files with 2832 additions and 0 deletions
/*
* Copyright 2014-2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.subtypes;
import com.google.common.base.MoreObjects;
import org.onlab.packet.Ip4Address;
/**
* Defines the OSPF external destination.
*/
public class OspfExternalDestination {
private boolean isType1orType2Metric;
private int metric;
private Ip4Address forwardingAddress;
private int externalRouterTag;
/**
* Gets whether type1 or type 2 metric.
*
* @return true if Type1 or false if Type2 metric
*/
public boolean isType1orType2Metric() {
return isType1orType2Metric;
}
/**
* Sets whether type1 or Type2 metric.
*
* @param isType1orType2Metric is type 1 or type 2 metric
*/
public void setType1orType2Metric(boolean isType1orType2Metric) {
this.isType1orType2Metric = isType1orType2Metric;
}
/**
* Gets the metric value.
*
* @return metric value
*/
public int metric() {
return metric;
}
/**
* Sets the metric value.
*
* @param metric metric value
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Gets forwarding address.
*
* @return forwarding address
*/
public Ip4Address forwardingAddress() {
return forwardingAddress;
}
/**
* Sets forwarding address.
*
* @param forwardingAddress forwarding address
*/
public void setForwardingAddress(Ip4Address forwardingAddress) {
this.forwardingAddress = forwardingAddress;
}
/**
* Gets external router tag.
*
* @return external router tag
*/
public int externalRouterTag() {
return externalRouterTag;
}
/**
* Sets external router tag.
*
* @param externalRouterTag external router tag
*/
public void setExternalRouterTag(int externalRouterTag) {
this.externalRouterTag = externalRouterTag;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("isType1orType2Metric", isType1orType2Metric)
.add("metric", metric)
.add("forwardingAddress", forwardingAddress)
.add("externalRouterTag", externalRouterTag)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.subtypes;
import com.google.common.base.MoreObjects;
/**
* Representation of an OSPF LSA link.
*/
public class OspfLsaLink {
public String linkId;
public String linkData;
public int linkType;
public int metric;
public int tos;
/**
* Gets link id.
*
* @return link id
*/
public String linkId() {
return linkId;
}
/**
* Sets link id.
*
* @param linkId link id
*/
public void setLinkId(String linkId) {
this.linkId = linkId;
}
/**
* Gets link data.
*
* @return link data
*/
public String linkData() {
return linkData;
}
/**
* Sets link data.
*
* @param linkData link data
*/
public void setLinkData(String linkData) {
this.linkData = linkData;
}
/**
* Gets link type.
*
* @return link type
*/
public int linkType() {
return linkType;
}
/**
* Sets link type.
*
* @param linkType link type
*/
public void setLinkType(int linkType) {
this.linkType = linkType;
}
/**
* Gets metric value.
*
* @return metric.
*/
public int metric() {
return metric;
}
/**
* Sets metric value.
*
* @param metric metric
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Gets tos.
*
* @return tos
*/
public int tos() {
return tos;
}
/**
* Sets tos.
*
* @param tos tos
*/
public void setTos(int tos) {
this.tos = tos;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("linkID", linkId)
.add("linkData", linkData)
.add("linkType", linkType)
.add("metric", metric)
.add("tos", tos)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an ASBR Summary LSA and methods to access them.
*/
public class AsbrSummaryLsa extends LsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 3 or 4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link State ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network Mask |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 | metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TOS | TOS metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
Summary LSA format
REFERENCE : RFC 2328
*/
private Ip4Address networkMask;
private int metric;
/**
* Creates an instance of ASBR Summary LSA.
*
* @param lsaHeader lsa header instance.
*/
public AsbrSummaryLsa(LsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Gets network mask.
*
* @return networkMask network mask
*/
public Ip4Address networkMask() {
return networkMask;
}
/**
* Sets network mask.
*
* @param networkMask network mask
*/
public void setNetworkMask(Ip4Address networkMask) {
this.networkMask = networkMask;
}
/**
* Gets metric value.
*
* @return metric value
*/
public int metric() {
return metric;
}
/**
* Sets metric value.
*
* @param metric metric value
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channelBuffer instance.
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
int unusedByte = channelBuffer.readByte();
this.setMetric(channelBuffer.readUnsignedMedium());
} catch (Exception e) {
log.debug("Error::AsbrSummaryLsa:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
/**
* Gets LSA bytes as array.
*
* @return LSA message as bytes
* @throws OspfParseException might throws exception while parsing packet
*/
public byte[] asBytes() throws OspfParseException {
byte[] lsaMessage = null;
byte[] lsaHeader = getLsaHeaderAsByteArray();
byte[] lsaBody = getLsaBodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Get LSA body as byte array.
*
* @return byte array contains lsa body
* @throws OspfParseException might throws exception while parsing packet
*/
public byte[] getLsaBodyAsByteArray() throws OspfParseException {
List<Byte> bodyLst = new ArrayList<>();
try {
bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.metric())));
} catch (Exception e) {
log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
return Bytes.toArray(bodyLst);
}
@Override
public OspfLsaType getOspfLsaType() {
return OspfLsaType.ASBR_SUMMARY;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AsbrSummaryLsa that = (AsbrSummaryLsa) o;
return Objects.equal(networkMask, that.networkMask) &&
Objects.equal(metric, that.metric);
}
@Override
public int hashCode() {
return Objects.hashCode(networkMask, metric);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("networkMask", networkMask)
.add("metric", metric)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an External LSA and the fields and methods to access them.
*/
public class ExternalLsa extends LsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 5 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link State ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network Mask |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|E| 0 | metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Forwarding address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| External Route Tag |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|E| TOS | TOS metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Forwarding address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| External Route Tag |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
External LSA format
REFERENCE : RFC 2328
*/
private static final Logger log =
LoggerFactory.getLogger(ExternalLsa.class);
private Ip4Address networkMask;
private List<OspfExternalDestination> externalDestinations = new ArrayList<>();
/**
* Creates an instance of External LSA.
*
* @param lsaHeader lsa header instance.
*/
public ExternalLsa(LsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Gets the network mask.
*
* @return networkMask
*/
public Ip4Address networkMask() {
return networkMask;
}
/**
* Sets network mask.
*
* @param networkMask network mask
*/
public void setNetworkMask(Ip4Address networkMask) {
this.networkMask = networkMask;
}
/**
* Adds the external destination details to the list.
*
* @param externalDestination external destination details
*/
public void addExternalDestination(OspfExternalDestination externalDestination) {
if (!externalDestinations.contains(externalDestination)) {
externalDestinations.add(externalDestination);
}
}
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channelBuffer instance
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) {
OspfExternalDestination externalDestination = new OspfExternalDestination();
//E Bit - use to find type1 or type2
int eIsSet = channelBuffer.readByte();
if (eIsSet != 0) {
externalDestination.setType1orType2Metric(true);
} else {
externalDestination.setType1orType2Metric(false);
}
externalDestination.setMetric(channelBuffer.readUnsignedMedium());
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray));
externalDestination.setExternalRouterTag(channelBuffer.readInt());
this.addExternalDestination(externalDestination);
}
} catch (Exception e) {
log.debug("Error::ExternalLSA:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
/**
* Gets LSA as bytes.
*
* @return LSA as bytes.
* @throws OspfParseException might throws exception while parsing packet
*/
public byte[] asBytes() throws OspfParseException {
byte[] lsaMessage = null;
byte[] lsaHeader = getLsaHeaderAsByteArray();
byte[] lsaBody = getLsaBodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Gets LSA body as byte array.
*
* @return byte array contains LSA body
* @throws OspfParseException might throws exception while parsing buffer
*/
public byte[] getLsaBodyAsByteArray() throws OspfParseException {
List<Byte> bodyLst = new ArrayList<>();
try {
bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
//add each OSPFExternalDestination details
for (OspfExternalDestination externalDest : externalDestinations) {
if (externalDest.isType1orType2Metric()) {
//add 1 followed by 7 zeros equals to decimal 128
bodyLst.add((byte) 128);
} else {
bodyLst.add((byte) 0);
}
bodyLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(externalDest.metric())));
bodyLst.addAll(Bytes.asList(externalDest.forwardingAddress().toOctets()));
bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(externalDest.externalRouterTag())));
}
} catch (Exception e) {
log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
return Bytes.toArray(bodyLst);
}
return Bytes.toArray(bodyLst);
}
@Override
public OspfLsaType getOspfLsaType() {
return OspfLsaType.EXTERNAL_LSA;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
ExternalLsa that = (ExternalLsa) other;
return Objects.equal(networkMask, that.networkMask) &&
Objects.equal(externalDestinations, that.externalDestinations);
}
@Override
public int hashCode() {
return Objects.hashCode(networkMask, externalDestinations);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("networkMask", networkMask)
.add("externalDestinations", externalDestinations)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of a Network LSA and fields and methods to access them.
*/
public class NetworkLsa extends LsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link State ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network Mask |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Attached Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
*/
private static final Logger log =
LoggerFactory.getLogger(NetworkLsa.class);
private Ip4Address networkMask;
private List<Ip4Address> attachedRouters = new ArrayList<>();
/**
* Creates an instance of Network LSA.
*/
public NetworkLsa() {
}
/**
* Creates an instance of Network LSA.
*
* @param lsaHeader lsa header instance.
*/
public NetworkLsa(LsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Gets network mask.
*
* @return network mask
*/
public Ip4Address networkMask() {
return networkMask;
}
/**
* Sets network mask.
*
* @param networkMask network mask
*/
public void setNetworkMask(Ip4Address networkMask) {
this.networkMask = networkMask;
}
/**
* Adds attached router to list.
*
* @param attachedRouter attached router ip address.
*/
public void addAttachedRouter(Ip4Address attachedRouter) {
attachedRouters.add(attachedRouter);
}
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channel buffer instance
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
//add all the attached routers
while (channelBuffer.readableBytes() > 0) {
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.addAttachedRouter(Ip4Address.valueOf(tempByteArray));
}
} catch (Exception e) {
log.debug("Error::NetworkLSA::readFrom:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
/**
* Gets LSA as bytes.
*
* @return LSA as byte array
* @throws OspfParseException might throws exception while parsing packet
*/
public byte[] asBytes() throws OspfParseException {
byte[] lsaMessage = null;
byte[] lsaHeader = getLsaHeaderAsByteArray();
byte[] lsaBody = getLSABodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Gets LSA body as byte array.
*
* @return LSA body as byte array
* @throws OspfParseException might throws exception while parsing packet
*/
public byte[] getLSABodyAsByteArray() throws OspfParseException {
List<Byte> bodyLst = new ArrayList<>();
try {
bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
//add each attachedRouters details
for (Ip4Address attachedRouter : attachedRouters) {
//attached router
bodyLst.addAll(Bytes.asList(attachedRouter.toOctets()));
}
} catch (Exception e) {
log.debug("Error::NetworkLSA::getLsrBodyAsByteArray {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
return Bytes.toArray(bodyLst);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
NetworkLsa that = (NetworkLsa) o;
return Objects.equal(networkMask, that.networkMask) &&
Objects.equal(attachedRouters, that.attachedRouters);
}
@Override
public int hashCode() {
return Objects.hashCode(networkMask, attachedRouters);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("networkMask", networkMask)
.add("attachedRouters", attachedRouters)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
/**
* Representation of an Opaque LSA of type AS (11).
*/
public class OpaqueLsa11 extends OpaqueLsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 9, 10 or 11 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque Type | Opaque ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| Opaque Information |
+ +
| ... |
*/
private byte[] opaqueInfo = null;
/**
* Creates an instance of Opaque type 11 LSA.
*
* @param lsaHeader LSA header instance
*/
public OpaqueLsa11(OpaqueLsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Reads from channel buffer and populate this.
*
* @param channelBuffer channelBuffer instance.
*/
public void readFrom(ChannelBuffer channelBuffer) {
int length = channelBuffer.readableBytes();
opaqueInfo = new byte[length];
channelBuffer.readBytes(opaqueInfo, 0, length);
}
/**
* Returns instance as bytes.
*
* @return instance as bytes
*/
public byte[] asBytes() {
byte[] lsaMessage = null;
byte[] lsaHeader = getOpaqueLsaHeaderAsByteArray();
byte[] lsaBody = getLsaBodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Get the LSA body as byte array.
*
* @return LSA body as byte array
*/
public byte[] getLsaBodyAsByteArray() {
return opaqueInfo;
}
@Override
public OspfLsaType getOspfLsaType() {
return OspfLsaType.AS_OPAQUE_LSA;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OpaqueLsa11 that = (OpaqueLsa11) o;
return Objects.equal(opaqueInfo, that.opaqueInfo);
}
@Override
public int hashCode() {
return Objects.hashCode(opaqueInfo);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("opaqueInfo", opaqueInfo)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
/**
* Representation of an Opaque LSA of type link local (9).
*/
public class OpaqueLsa9 extends OpaqueLsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 9, 10 or 11 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque Type | Opaque ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| Opaque Information |
+ +
| ... |
*/
private byte[] opaqueInfo = null;
/**
* Creates an instance of Opaque type 9 LSA.
*
* @param lsaHeader LSA header instance
*/
public OpaqueLsa9(OpaqueLsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channelBuffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
int length = channelBuffer.readableBytes();
opaqueInfo = new byte[length];
channelBuffer.readBytes(opaqueInfo, 0, length);
}
/**
* Returns instance as bytes.
*
* @return instance as bytes
*/
public byte[] asBytes() {
byte[] lsaMessage = null;
byte[] lsaHeader = getOpaqueLsaHeaderAsByteArray();
byte[] lsaBody = getLsaBodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Gets the LSA body.
*
* @return the LSA body
*/
public byte[] getLsaBodyAsByteArray() {
return opaqueInfo;
}
@Override
public OspfLsaType getOspfLsaType() {
return OspfLsaType.LINK_LOCAL_OPAQUE_LSA;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OpaqueLsa9 that = (OpaqueLsa9) o;
return Objects.equal(opaqueInfo, that.opaqueInfo);
}
@Override
public int hashCode() {
return Objects.hashCode(opaqueInfo);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("opaqueInfo", opaqueInfo)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.primitives.Bytes;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.exceptions.OspfErrorType;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of a Summary LSA, fields and methods to access them.
*/
public class SummaryLsa extends LsaHeader {
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS age | Options | 3 or 4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link State ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Advertising Router |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LS checksum | length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network Mask |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 | metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TOS | TOS metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
*/
private static final Logger log = LoggerFactory.getLogger(SummaryLsa.class);
private Ip4Address networkMask;
private int metric;
/**
* Creates an instance of Summary LSA.
*
* @param lsaHeader LSA header instance
*/
public SummaryLsa(LsaHeader lsaHeader) {
populateHeader(lsaHeader);
}
/**
* Gets network mask.
*
* @return network mask
*/
public Ip4Address networkMask() {
return networkMask;
}
/**
* Sets network mask.
*
* @param networkMask network mask
*/
public void setNetworkMask(Ip4Address networkMask) {
this.networkMask = networkMask;
}
/**
* Gets metric value.
*
* @return metric
*/
public int metric() {
return metric;
}
/**
* Sets metric value.
*
* @param metric metric value
*/
public void setMetric(int metric) {
this.metric = metric;
}
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channelBuffer instance
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
int unsedByte = channelBuffer.readByte();
this.setMetric(channelBuffer.readUnsignedMedium());
} catch (Exception e) {
log.debug("Error::SummaryLsa:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
/**
* Returns instance as bytes.
*
* @return instance as bytes
*/
public byte[] asBytes() {
byte[] lsaMessage = null;
byte[] lsaHeader = getLsaHeaderAsByteArray();
byte[] lsaBody = getLsaBodyAsByteArray();
lsaMessage = Bytes.concat(lsaHeader, lsaBody);
return lsaMessage;
}
/**
* Get the LSA body.
*
* @return LSA body
*/
public byte[] getLsaBodyAsByteArray() {
List<Byte> bodyLst = new ArrayList<>();
try {
bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
bodyLst.add((byte) 0);
bodyLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(this.metric())));
} catch (Exception e) {
log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
return Bytes.toArray(bodyLst);
}
return Bytes.toArray(bodyLst);
}
@Override
public OspfLsaType getOspfLsaType() {
return OspfLsaType.SUMMARY;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("networkMask", networkMask)
.add("metric", metric)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SummaryLsa that = (SummaryLsa) o;
return Objects.equal(networkMask, that.networkMask) &&
Objects.equal(metric, that.metric);
}
@Override
public int hashCode() {
return Objects.hashCode(networkMask, metric);
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
/**
* Marker interface represents a top level TLV in an Opaque LSA.
*/
public interface TopLevelTlv {
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.subtypes;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import java.net.InetAddress;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for OspfRouterId.
*/
public class OspfExternalDestinationTest {
private OspfExternalDestination ospfExternalDestination;
@Before
public void setUp() throws Exception {
ospfExternalDestination = new OspfExternalDestination();
}
@After
public void tearDown() throws Exception {
ospfExternalDestination = null;
}
/**
* Tests isType1orType2Metric() getter method.
*/
@Test
public void testIsType1orType2Metric() throws Exception {
ospfExternalDestination.setType1orType2Metric(true);
assertThat(ospfExternalDestination.isType1orType2Metric(), is(true));
}
/**
* Tests isType1orType2Metric() setter method.
*/
@Test
public void testSetType1orType2Metric() throws Exception {
ospfExternalDestination.setType1orType2Metric(true);
assertThat(ospfExternalDestination.isType1orType2Metric(), is(true));
}
/**
* Tests metric() getter method.
*/
@Test
public void testGetMetric() throws Exception {
ospfExternalDestination.setMetric(100);
assertThat(ospfExternalDestination.metric(), is(100));
}
/**
* Tests metric() setter method.
*/
@Test
public void testSetMetric() throws Exception {
ospfExternalDestination.setMetric(100);
assertThat(ospfExternalDestination.metric(), is(100));
}
/**
* Tests forwardingAddress() getter method.
*/
@Test
public void testGetForwardingAddress() throws Exception {
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost())));
}
/**
* Tests forwardingAddress() setter method.
*/
@Test
public void testSetForwardingAddress() throws Exception {
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost())));
}
/**
* Tests externalRouterTag() getter method.
*/
@Test
public void testGetExternalRouterTag() throws Exception {
ospfExternalDestination.setExternalRouterTag(100);
assertThat(ospfExternalDestination.externalRouterTag(), is(100));
}
/**
* Tests externalRouterTag() setter method.
*/
@Test
public void testSetExternalRouterTag() throws Exception {
ospfExternalDestination.setExternalRouterTag(100);
assertThat(ospfExternalDestination.externalRouterTag(), is(100));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(ospfExternalDestination.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.subtypes;
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 OspfLsaLink.
*/
public class OspfLsaLinkTest {
private OspfLsaLink ospfLsaLink;
@Before
public void setUp() throws Exception {
ospfLsaLink = new OspfLsaLink();
}
@After
public void tearDown() throws Exception {
ospfLsaLink = null;
}
/**
* Tests linkId() getter method.
*/
@Test
public void testGetLinkID() throws Exception {
ospfLsaLink.setLinkId("1.1.1.1");
assertThat(ospfLsaLink.linkId(), is("1.1.1.1"));
}
/**
* Tests linkId() setter method.
*/
@Test
public void testSetLinkID() throws Exception {
ospfLsaLink.setLinkId("1.1.1.1");
assertThat(ospfLsaLink.linkId(), is("1.1.1.1"));
}
/**
* Tests linkData() getter method.
*/
@Test
public void testGetLinkData() throws Exception {
ospfLsaLink.setLinkData("1.1.1.1");
assertThat(ospfLsaLink.linkData(), is("1.1.1.1"));
}
/**
* Tests linkData() setter method.
*/
@Test
public void testSetLinkData() throws Exception {
ospfLsaLink.setLinkData("1.1.1.1");
assertThat(ospfLsaLink.linkData(), is("1.1.1.1"));
}
/**
* Tests linkType() getter method.
*/
@Test
public void testGetLinkType() throws Exception {
ospfLsaLink.setLinkType(1);
assertThat(ospfLsaLink.linkType(), is(1));
}
/**
* Tests linkType() setter method.
*/
@Test
public void testSetLinkType() throws Exception {
ospfLsaLink.setLinkType(1);
assertThat(ospfLsaLink.linkType(), is(1));
}
/**
* Tests metric() getter method.
*/
@Test
public void testGetMetric() throws Exception {
ospfLsaLink.setMetric(100);
assertThat(ospfLsaLink.metric(), is(100));
}
/**
* Tests metric() setter method.
*/
@Test
public void testSetMetric() throws Exception {
ospfLsaLink.setMetric(100);
assertThat(ospfLsaLink.metric(), is(100));
}
/**
* Tests tos() getter method.
*/
@Test
public void testGetTos() throws Exception {
ospfLsaLink.setTos(100);
assertThat(ospfLsaLink.tos(), is(100));
}
/**
* Tests tos() setter method.
*/
@Test
public void testSetTos() throws Exception {
ospfLsaLink.setTos(100);
assertThat(ospfLsaLink.tos(), is(100));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(ospfLsaLink.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for AsbrSummaryLsa.
*/
public class AsbrSummaryLsaTest {
private final Ip4Address ipAddress = Ip4Address.valueOf("10.226.165.164");
private AsbrSummaryLsa asbrSummaryLsa;
private Ip4Address result;
private int result1;
private int num;
private byte[] inputByteArray;
private byte[] result2;
private ChannelBuffer channelBuffer;
private LsaHeader lsaHeader;
private OspfLsaType ospflsaType;
private String result3;
private boolean result4;
@Before
public void setUp() throws Exception {
asbrSummaryLsa = new AsbrSummaryLsa(new LsaHeader());
}
@After
public void tearDown() throws Exception {
asbrSummaryLsa = null;
}
/**
* Tests networkMask() getter method.
*/
@Test
public void testGetNetworkMask() throws Exception {
asbrSummaryLsa.setNetworkMask(ipAddress);
result = asbrSummaryLsa.networkMask();
assertThat(result, is(notNullValue()));
assertThat(result, is(ipAddress));
}
/**
* Tests networkMask() setter method.
*/
@Test
public void testSetNetworkMask() throws Exception {
asbrSummaryLsa.setNetworkMask(ipAddress);
result = asbrSummaryLsa.networkMask();
assertThat(result, is(notNullValue()));
assertThat(result, is(ipAddress));
}
/**
* Tests metric() getter method.
*/
@Test
public void testGetMetric() throws Exception {
num = 10;
asbrSummaryLsa.setMetric(num);
result1 = asbrSummaryLsa.metric();
assertThat(result1, is(notNullValue()));
assertThat(result1, is(num));
}
/**
* Tests metric() setter method.
*/
@Test
public void testSetMetric() throws Exception {
num = 20;
asbrSummaryLsa.setMetric(num);
result1 = asbrSummaryLsa.metric();
assertThat(result1, is(notNullValue()));
assertThat(result1, is(num));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
inputByteArray = createByteForNetworkLsa();
lsaHeader = createLsaHeader();
asbrSummaryLsa = new AsbrSummaryLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
asbrSummaryLsa.readFrom(channelBuffer);
assertThat(asbrSummaryLsa, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
byte[] temp = {0, 1, 2, 3};
inputByteArray = temp;
lsaHeader = createLsaHeader();
asbrSummaryLsa = new AsbrSummaryLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
asbrSummaryLsa.readFrom(channelBuffer);
assertThat(asbrSummaryLsa, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test(expected = Exception.class)
public void testAsBytes() throws Exception {
result2 = asbrSummaryLsa.asBytes();
assertThat(result2, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test(expected = Exception.class)
public void testGetLsaBodyAsByteArray() throws Exception {
result2 = asbrSummaryLsa.getLsaBodyAsByteArray();
assertThat(result2, is(notNullValue()));
}
/**
* Tests ospfLsaType() getter method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
ospflsaType = asbrSummaryLsa.getOspfLsaType();
assertThat(ospflsaType, is(notNullValue()));
assertThat(ospflsaType, is(OspfLsaType.ASBR_SUMMARY));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
result3 = asbrSummaryLsa.toString();
assertThat(result3, is(notNullValue()));
}
/**
* Tests hashcode() method.
*/
@Test
public void testHashcode() throws Exception {
result1 = asbrSummaryLsa.hashCode();
assertThat(result1, is(notNullValue()));
}
/**
* Tests equals() method.
*/
@Test
public void testEqual() throws Exception {
result4 = asbrSummaryLsa.equals(new AsbrSummaryLsa(new LsaHeader()));
assertThat(result4, is(true));
}
/**
* Utility method used by junit methods.
*/
private byte[] createByteForNetworkLsa() {
byte[] packet = {2, 1, 1, 52, -64, -88, 56, 1, -64, -88, 56, 1, 0, 100, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, -64,
-88, 56, 1, 0, 10, 1, 1, 0, 0, 0, 40, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56,
1};
return packet;
}
/**
* Utility method used by junit methods.
*/
private LsaHeader createLsaHeader() {
lsaHeader = new LsaHeader();
lsaHeader.setLsType(1);
lsaHeader.setLsPacketLen(48);
lsaHeader.setLsCheckSum(10);
lsaHeader.setAge(4);
lsaHeader.setLinkStateId("10.226.165.164");
lsaHeader.setLsSequenceNo(250);
lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
lsaHeader.setOptions(2);
return lsaHeader;
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for ExternalLsa.
*/
public class ExternalLsaTest {
private ExternalLsa externalLsa;
private Vector<OspfExternalDestination> externalDestinations = new Vector<OspfExternalDestination>();
private Ip4Address result;
private OspfExternalDestination ospfExternalDestination;
private OspfExternalDestination ospfExternalDestination1;
private LsaHeader lsaHeader;
private byte[] inputByteArray;
private ChannelBuffer channelBuffer;
private byte[] result1;
private OspfLsaType ospflsaType;
private int result2;
@Before
public void setUp() throws Exception {
externalLsa = new ExternalLsa(new LsaHeader());
}
@After
public void tearDown() throws Exception {
externalLsa = null;
externalDestinations = null;
result = null;
ospfExternalDestination = null;
ospfExternalDestination1 = null;
lsaHeader = null;
inputByteArray = null;
channelBuffer = null;
result1 = null;
ospflsaType = null;
}
/**
* Tests networkMask() getter method.
*/
@Test
public void testGetNetworkMask() throws Exception {
externalLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
result = externalLsa.networkMask();
assertThat(result, is(notNullValue()));
assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
}
/**
* Tests networkMask() setter method.
*/
@Test
public void testSetNetworkMask() throws Exception {
externalLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
result = externalLsa.networkMask();
assertThat(result, is(notNullValue()));
assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
}
/**
* Tests addExternalDesitnation() method.
*/
@Test
public void testAddExternalDesitnation() throws Exception {
externalLsa.addExternalDestination(createOspfExternalDestination());
assertThat(externalLsa, is(notNullValue()));
}
/**
* Tests hashCode() method.
*/
@Test
public void testHashcode() throws Exception {
result2 = externalLsa.hashCode();
assertThat(result2, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
ospfExternalDestination = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(2);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination);
ospfExternalDestination1 = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(3);
ospfExternalDestination.setMetric(50);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
inputByteArray = createByteForNetworkLsa();
lsaHeader = createLsaHeader();
externalLsa = new ExternalLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
externalLsa.readFrom(channelBuffer);
assertThat(externalLsa, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
ospfExternalDestination = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(2);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination);
ospfExternalDestination1 = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(3);
ospfExternalDestination.setMetric(50);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
byte[] temp = {0, 0, 0};
inputByteArray = temp;
lsaHeader = createLsaHeader();
externalLsa = new ExternalLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
externalLsa.readFrom(channelBuffer);
assertThat(externalLsa, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result1 = externalLsa.asBytes();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray() throws Exception {
ospfExternalDestination = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(2);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination);
ospfExternalDestination1 = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(3);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
result1 = externalLsa.getLsaBodyAsByteArray();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray1() throws Exception {
externalLsa.setNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfExternalDestination = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(2);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination);
ospfExternalDestination1 = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(3);
ospfExternalDestination.setMetric(100);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
result1 = externalLsa.getLsaBodyAsByteArray();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getOspfLsaType() getter method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
ospflsaType = externalLsa.getOspfLsaType();
assertThat(ospflsaType, is(notNullValue()));
assertThat(ospflsaType, is(OspfLsaType.EXTERNAL_LSA));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(externalLsa.toString(), is(notNullValue()));
}
/**
* Utility method used by junit methods.
*/
private byte[] createByteForNetworkLsa() {
byte[] packet = {2, 1, 1, 52, -64, -88, 56, 1, -64, -88, 56, 1, 0, 100, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, -64,
-88, 56, 1, 0, 10, 1, 1, 0, 0, 0, 40, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56,
1};
return packet;
}
/**
* Utility method used by junit methods.
*/
private LsaHeader createLsaHeader() {
lsaHeader = new LsaHeader();
lsaHeader.setLsType(1);
lsaHeader.setLsPacketLen(48);
lsaHeader.setLsCheckSum(10);
lsaHeader.setAge(4);
lsaHeader.setLinkStateId("10.226.165.164");
lsaHeader.setLsSequenceNo(250);
lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
lsaHeader.setOptions(2);
return lsaHeader;
}
/**
* Utility method used by junit methods.
*/
private OspfExternalDestination createOspfExternalDestination() throws UnknownHostException {
ospfExternalDestination = new OspfExternalDestination();
ospfExternalDestination.setExternalRouterTag(1);
ospfExternalDestination.setMetric(10);
ospfExternalDestination.setType1orType2Metric(true);
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
return ospfExternalDestination;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import java.net.InetAddress;
import java.util.Vector;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for NetworkLsa.
*/
public class NetworkLsaTest {
private Vector<String> attachedRouters = new Vector();
private NetworkLsa networkLsa;
private Ip4Address result;
private Ip4Address inetAddres;
private byte[] inputByteArray;
private LsaHeader lsaHeader;
private ChannelBuffer channelBuffer;
private byte[] result1;
private OspfLsaType ospflsaType;
private int result2;
@Before
public void setUp() throws Exception {
networkLsa = new NetworkLsa();
}
@After
public void tearDown() throws Exception {
networkLsa = null;
attachedRouters = null;
result = null;
inetAddres = null;
inputByteArray = null;
lsaHeader = null;
channelBuffer = null;
result1 = null;
ospflsaType = null;
}
/**
* Tests networkMask() getter method.
*/
@Test
public void testGetNetworkMask() throws Exception {
networkLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
result = networkLsa.networkMask();
assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
}
/**
* Tests networkMask() setter method.
*/
@Test
public void testSetNetworkMask() throws Exception {
networkLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.165"));
result = networkLsa.networkMask();
result = networkLsa.networkMask();
assertThat(result, is(Ip4Address.valueOf("10.226.165.165")));
}
/**
* Tests addAttachedRouter() getter method.
*/
@Test
public void testGetAttachedRouters() throws Exception {
attachedRouters.add("1.1.1.1");
networkLsa.addAttachedRouter(Ip4Address.valueOf("1.1.1.1"));
assertThat(attachedRouters, is(notNullValue()));
}
/**
* Tests addAttachedRouter() setter method.
*/
@Test
public void testSetAttachedRouters() throws Exception {
attachedRouters.add("1.1.1.1");
networkLsa.addAttachedRouter(Ip4Address.valueOf("1.1.1.1"));
assertThat(attachedRouters, is(notNullValue()));
}
/**
* Tests addAttachedRouter() method.
*/
@Test
public void testAddAttachedRouter() throws Exception {
inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost());
networkLsa.addAttachedRouter(inetAddres);
inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost());
networkLsa.addAttachedRouter(inetAddres);
assertThat(networkLsa, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
inputByteArray = createByteForNetworkLsa();
lsaHeader = createLsaHeader();
networkLsa = new NetworkLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
networkLsa.readFrom(channelBuffer);
assertThat(networkLsa, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
byte[] temp = {0, 0, 0};
inputByteArray = temp;
lsaHeader = createLsaHeader();
networkLsa = new NetworkLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
networkLsa.readFrom(channelBuffer);
assertThat(networkLsa, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test(expected = Exception.class)
public void testAsBytes() throws Exception {
result1 = networkLsa.asBytes();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test(expected = Exception.class)
public void testGetLsaBodyAsByteArray() throws Exception {
networkLsa.addAttachedRouter(Ip4Address.valueOf("1.1.1.1"));
networkLsa.addAttachedRouter(Ip4Address.valueOf("2.2.2.2"));
networkLsa.addAttachedRouter(Ip4Address.valueOf("3.3.3.3"));
result1 = networkLsa.getLSABodyAsByteArray();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray1() throws Exception {
networkLsa.setNetworkMask(Ip4Address.valueOf("255.255.255.255"));
networkLsa.addAttachedRouter(Ip4Address.valueOf("1.1.1.1"));
networkLsa.addAttachedRouter(Ip4Address.valueOf("2.2.2.2"));
networkLsa.addAttachedRouter(Ip4Address.valueOf("3.3.3.3"));
result1 = networkLsa.getLSABodyAsByteArray();
assertThat(result1, is(notNullValue()));
}
/**
* Tests getOspfLsaType() getter method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
networkLsa.setLsType(2);
ospflsaType = networkLsa.getOspfLsaType();
assertThat(ospflsaType, is(OspfLsaType.NETWORK));
}
/**
* Tests hashCode() method.
*/
@Test
public void testHashcode() throws Exception {
result2 = networkLsa.hashCode();
assertThat(result2, is(notNullValue()));
}
/**
* Utility method used by junit methods.
*/
private byte[] createByteForNetworkLsa() {
byte[] packet = {2, 1, 1, 52, -64, -88, 56, 1, -64, -88, 56, 1, 0, 100, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, -64,
-88, 56, 1, 0, 10, 1, 1, 0, 0, 0, 40, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56,
1};
return packet;
}
/**
* Utility method used by junit methods.
*/
private LsaHeader createLsaHeader() {
lsaHeader = new LsaHeader();
lsaHeader.setLsType(2);
lsaHeader.setLsPacketLen(48);
lsaHeader.setLsCheckSum(10);
lsaHeader.setAge(4);
lsaHeader.setLinkStateId("10.226.165.164");
lsaHeader.setLsSequenceNo(250);
lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
lsaHeader.setOptions(2);
return lsaHeader;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for OpaqueLsa11.
*/
public class OpaqueLsa11Test {
private final byte[] packet = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private OpaqueLsa11 opaqueLsa11;
private OpaqueLsaHeader opqueHeader;
private ChannelBuffer channelBuffer;
private byte[] result;
private int result1;
private String result2;
private OspfLsaType ospflsaType;
@Before
public void setUp() throws Exception {
opaqueLsa11 = new OpaqueLsa11(new OpaqueLsaHeader());
}
@After
public void tearDown() throws Exception {
opaqueLsa11 = null;
opqueHeader = null;
channelBuffer = null;
result = null;
ospflsaType = null;
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(11);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(1);
opqueHeader.setOpaqueType(11);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa11 = new OpaqueLsa11(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa11.readFrom(channelBuffer);
assertThat(opaqueLsa11, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(11);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(1);
opqueHeader.setOpaqueType(11);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa11 = new OpaqueLsa11(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa11.readFrom(channelBuffer);
result = opaqueLsa11.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(11);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(1);
opqueHeader.setOpaqueType(11);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa11 = new OpaqueLsa11(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa11.readFrom(channelBuffer);
result = opaqueLsa11.getLsaBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests getOspfLsaType() method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
opaqueLsa11.setLsType(11);
ospflsaType = opaqueLsa11.getOspfLsaType();
assertThat(ospflsaType, is(notNullValue()));
assertThat(ospflsaType, is(OspfLsaType.AS_OPAQUE_LSA));
}
/**
* Tests hashCode() method.
*/
@Test
public void testHashcode() throws Exception {
result1 = opaqueLsa11.hashCode();
assertThat(result1, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
result2 = opaqueLsa11.toString();
assertThat(result2, is(notNullValue()));
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for OpaqueLsa9.
*/
public class OpaqueLsa9Test {
private final byte[] packet = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};
private byte[] result;
private String result1;
private OpaqueLsaHeader opqueHeader;
private OpaqueLsa9 opaqueLsa9;
private ChannelBuffer channelBuffer;
private OspfLsaType ospflsaType;
private int result2;
@Before
public void setUp() throws Exception {
opaqueLsa9 = new OpaqueLsa9(new OpaqueLsaHeader());
}
@After
public void tearDown() throws Exception {
opaqueLsa9 = null;
opqueHeader = null;
channelBuffer = null;
result = null;
ospflsaType = null;
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(1);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(9);
opqueHeader.setOpaqueType(9);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa9 = new OpaqueLsa9(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa9.readFrom(channelBuffer);
assertThat(opaqueLsa9, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(9);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(9);
opqueHeader.setOpaqueType(9);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa9 = new OpaqueLsa9(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa9.readFrom(channelBuffer);
result = opaqueLsa9.asBytes();
assertThat(result, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray() throws Exception {
opqueHeader = new OpaqueLsaHeader();
opqueHeader.setLsType(9);
opqueHeader.setLsPacketLen(48);
opqueHeader.setLsCheckSum(10);
opqueHeader.setAge(4);
opqueHeader.setOpaqueId(9);
opqueHeader.setOpaqueType(9);
opqueHeader.setLsSequenceNo(250);
opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
opqueHeader.setOptions(2);
opaqueLsa9 = new OpaqueLsa9(opqueHeader);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
opaqueLsa9.readFrom(channelBuffer);
result = opaqueLsa9.getLsaBodyAsByteArray();
assertThat(result, is(notNullValue()));
}
/**
* Tests hashCode() method.
*/
@Test
public void testHashcode() throws Exception {
result2 = opaqueLsa9.hashCode();
assertThat(result2, is(notNullValue()));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
result1 = opaqueLsa9.toString();
assertThat(result1, is(notNullValue()));
}
/**
* Tests to getOspfLsaType() getter method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
opaqueLsa9.setLsType(9);
ospflsaType = opaqueLsa9.getOspfLsaType();
assertThat(ospflsaType, is(notNullValue()));
assertThat(ospflsaType, is(OspfLsaType.LINK_LOCAL_OPAQUE_LSA));
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.protocol.lsa.types;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for SummaryLsa.
*/
public class SummaryLsaTest {
private SummaryLsa summaryLsa;
private Ip4Address result;
private int result1;
private byte[] inputByteArray;
private LsaHeader lsaHeader;
private ChannelBuffer channelBuffer;
private byte[] result2;
private OspfLsaType ospflsaType;
@Before
public void setUp() throws Exception {
summaryLsa = new SummaryLsa(new LsaHeader());
}
@After
public void tearDown() throws Exception {
summaryLsa = null;
result = null;
inputByteArray = null;
lsaHeader = null;
channelBuffer = null;
result2 = null;
ospflsaType = null;
}
/**
* Tests networkMask() getter method.
*/
@Test
public void testGetNetworkMask() throws Exception {
summaryLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
result = summaryLsa.networkMask();
assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
}
/**
* Tests networkMask() setter method.
*/
@Test
public void testSetNetworkMask() throws Exception {
summaryLsa.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
result = summaryLsa.networkMask();
assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
}
/**
* Tests metric() getter method.
*/
@Test
public void testGetMetric() throws Exception {
summaryLsa.setMetric(10);
result1 = summaryLsa.metric();
assertThat(result1, is(10));
}
/**
* Tests metric() setter method.
*/
@Test
public void testSetMetric() throws Exception {
summaryLsa.setMetric(20);
result1 = summaryLsa.metric();
assertThat(result1, is(20));
}
/**
* Tests readFrom() method.
*/
@Test
public void testReadFrom() throws Exception {
inputByteArray = createByteForNetworkLsa();
lsaHeader = createLsaHeader();
summaryLsa = new SummaryLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
summaryLsa.readFrom(channelBuffer);
assertThat(summaryLsa, is(notNullValue()));
}
/**
* Tests readFrom() method.
*/
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
byte[] temp = {0, 0, 0};
inputByteArray = temp;
lsaHeader = createLsaHeader();
summaryLsa = new SummaryLsa(lsaHeader);
channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
summaryLsa.readFrom(channelBuffer);
assertThat(summaryLsa, is(notNullValue()));
}
/**
* Tests asBytes() method.
*/
@Test
public void testAsBytes() throws Exception {
result2 = summaryLsa.asBytes();
assertThat(result2, is(notNullValue()));
}
/**
* Tests getLsaBodyAsByteArray() method.
*/
@Test
public void testGetLsaBodyAsByteArray() throws Exception {
result2 = summaryLsa.getLsaBodyAsByteArray();
assertThat(result2, is(notNullValue()));
}
/**
* Tests getOspfLsaType() getter method.
*/
@Test
public void testGetOspfLsaType() throws Exception {
ospflsaType = summaryLsa.getOspfLsaType();
assertThat(ospflsaType, is(notNullValue()));
assertThat(ospflsaType, is(OspfLsaType.SUMMARY));
}
/**
* Utility method used by junit methods.
*/
private byte[] createByteForNetworkLsa() {
byte[] packet = {2, 1, 1, 52, -64, -88, 56, 1, -64, -88, 56, 1, 0, 100, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, -64,
-88, 56, 1, 0, 10, 1, 1, 0, 0, 0, 40, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56,
1};
return packet;
}
/**
* Utility method used by junit methods.
*/
private LsaHeader createLsaHeader() {
lsaHeader = new LsaHeader();
lsaHeader.setLsType(3);
lsaHeader.setLsPacketLen(48);
lsaHeader.setLsCheckSum(10);
lsaHeader.setAge(4);
lsaHeader.setLinkStateId("10.226.165.164");
lsaHeader.setLsSequenceNo(250);
lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
lsaHeader.setOptions(2);
return lsaHeader;
}
/**
* Tests hashcode() method.
*/
@Test
public void testHashcode() throws Exception {
result1 = summaryLsa.hashCode();
assertThat(result1, is(notNullValue()));
}
}
\ No newline at end of file