Kiran Ramachandra
Committed by Gerrit Code Review

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

Change-Id: Ic37fcf98dfb6c7a15a124b495aee8517a8df23c9
Showing 31 changed files with 3219 additions and 0 deletions
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.onosproject.ospf.protocol.util.OspfUtil;
21 +
22 +import java.util.ArrayList;
23 +import java.util.List;
24 +
25 +/**
26 + * Representation of a TLV header.
27 + */
28 +public class TlvHeader {
29 + private int tlvType;
30 + private int tlvLength;
31 +
32 + /**
33 + * Gets TLV length.
34 + *
35 + * @return TLV length
36 + */
37 + public int tlvLength() {
38 + return tlvLength;
39 + }
40 +
41 + /**
42 + * Sets TLV length.
43 + *
44 + * @param tlvLength TLV length
45 + */
46 + public void setTlvLength(int tlvLength) {
47 + this.tlvLength = tlvLength;
48 + }
49 +
50 + /**
51 + * Gets TLV type.
52 + *
53 + * @return TLV type
54 + */
55 + public int tlvType() {
56 + return tlvType;
57 + }
58 +
59 + /**
60 + * Sets TLV type.
61 + *
62 + * @param tlvType TLV type
63 + */
64 + public void setTlvType(int tlvType) {
65 + this.tlvType = tlvType;
66 + }
67 +
68 + /**
69 + * Gets TLV header as bytes.
70 + *
71 + * @return TLV header as bytes
72 + */
73 + public byte[] getTlvHeaderAsByteArray() {
74 + List<Byte> headerLst = new ArrayList();
75 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvType)));
76 + headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvLength)));
77 + return Bytes.toArray(headerLst);
78 + }
79 +
80 + @Override
81 + public String toString() {
82 + return MoreObjects.toStringHelper(getClass())
83 + .omitNullValues()
84 + .add("tlvType", tlvType)
85 + .add("tlvLength", tlvLength)
86 + .toString();
87 + }
88 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.util.OspfUtil;
23 +
24 +/**
25 + * Representation of an administrative group value of link tlv of Traffic Engineering..
26 + */
27 +public class AdministrativeGroup extends TlvHeader implements LinkSubType {
28 +
29 + private int administrativeGroup;
30 +
31 + /**
32 + * Creates an administrative group instance.
33 + *
34 + * @param header Tlv Header instance
35 + */
36 + public AdministrativeGroup(TlvHeader header) {
37 + this.setTlvType(header.tlvType());
38 + this.setTlvLength(header.tlvLength());
39 + }
40 +
41 + /**
42 + * Gets administrative group value.
43 + *
44 + * @return administrative group value
45 + */
46 + public int administrativeGroup() {
47 + return administrativeGroup;
48 + }
49 +
50 + /**
51 + * Sets administrative group value.
52 + *
53 + * @param administrativeGroup value
54 + */
55 + public void setAdministrativeGroup(int administrativeGroup) {
56 + this.administrativeGroup = administrativeGroup;
57 + }
58 +
59 + /**
60 + * Gets administrative group value.
61 + *
62 + * @return administrativeGroup value
63 + */
64 + public int getAdministrativeGroupValue() {
65 + return this.administrativeGroup;
66 + }
67 +
68 + /**
69 + * Reads bytes from channel buffer.
70 + *
71 + * @param channelBuffer Channel buffer instance
72 + */
73 + public void readFrom(ChannelBuffer channelBuffer) {
74 + byte[] tempByteArray = new byte[tlvLength()];
75 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
76 + this.setAdministrativeGroup(OspfUtil.byteToInteger(tempByteArray));
77 + }
78 +
79 + /**
80 + * Returns administrative group as byte array.
81 + *
82 + * @return administrative group instance as byte array
83 + */
84 + public byte[] asBytes() {
85 + byte[] linkSubType = null;
86 +
87 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
88 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
89 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
90 +
91 + return linkSubType;
92 + }
93 +
94 + /**
95 + * Gets administrative group body as byte array.
96 + *
97 + * @return byte array of sub tlv administrative group
98 + */
99 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
100 +
101 + byte[] linkSubTypeBody;
102 + linkSubTypeBody = OspfUtil.convertToFourBytes(this.administrativeGroup);
103 +
104 + return linkSubTypeBody;
105 + }
106 +
107 + @Override
108 + public String toString() {
109 + return MoreObjects.toStringHelper(getClass())
110 + .add("administrativeGroup", administrativeGroup)
111 + .toString();
112 + }
113 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.exceptions.OspfErrorType;
22 +import org.onosproject.ospf.exceptions.OspfParseException;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +import org.onosproject.ospf.protocol.util.OspfUtil;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +import java.net.InetAddress;
29 +
30 +/**
31 + * Representation of link id value of link tlv of Traffic Engineering.
32 + */
33 +public class LinkId extends TlvHeader implements LinkSubType {
34 + private static final Logger log =
35 + LoggerFactory.getLogger(LinkId.class);
36 + private String linkId;
37 +
38 + /**
39 + * Creates an instance of link id.
40 + *
41 + * @param header tlv header instance
42 + */
43 + public LinkId(TlvHeader header) {
44 + this.setTlvType(header.tlvType());
45 + this.setTlvLength(header.tlvLength());
46 + }
47 +
48 + /**
49 + * Sets link type.
50 + *
51 + * @param linkType link type value
52 + */
53 + public void setLinkId(String linkType) {
54 + this.linkId = linkType;
55 + }
56 +
57 + /**
58 + * Reads bytes from channel buffer.
59 + *
60 + * @param channelBuffer channel buffer instance
61 + * @throws Exception might throws exception while parsing packet
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
64 + try {
65 + byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
66 + channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
67 + this.setLinkId(InetAddress.getByAddress(tempByteArray).getHostName());
68 + } catch (Exception e) {
69 + log.debug("Error::LinkId:: {}", e.getMessage());
70 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
71 + OspfErrorType.BAD_MESSAGE);
72 + }
73 + }
74 +
75 + /**
76 + * Returns instance as byte array.
77 + *
78 + * @return instance as bytes
79 + * @throws Exception might throws exception while parsing packet
80 + */
81 + public byte[] asBytes() throws Exception {
82 + byte[] linkSubType = null;
83 +
84 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
85 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
86 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
87 +
88 + return linkSubType;
89 + }
90 +
91 + /**
92 + * Gets byte array of link id sub tlv body.
93 + *
94 + * @return gets the body as byte array
95 + * @throws Exception might throws exception while parsing packet
96 + */
97 + public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
98 + byte[] linkSubTypeBody = null;
99 + try {
100 + linkSubTypeBody = InetAddress.getByName(this.linkId).getAddress();
101 + } catch (Exception e) {
102 + log.debug("Error::LinkId:: {}", e.getMessage());
103 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
104 + OspfErrorType.BAD_MESSAGE);
105 + }
106 + return linkSubTypeBody;
107 + }
108 +
109 + /**
110 + * Returns this instance as string.
111 + *
112 + * @return this instance as string
113 + */
114 + @Override
115 + public String toString() {
116 + return MoreObjects.toStringHelper(getClass())
117 + .add("linkId", linkId)
118 + .toString();
119 + }
120 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +/**
19 + * Marker interface to represent TE Link sub types.
20 + */
21 +public interface LinkSubType {
22 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +/**
19 + * Representation of TE link sub types.
20 + */
21 +public enum LinkSubTypes {
22 + LINK_TYPE(1),
23 + LINK_ID(2),
24 + LOCAL_INTERFACE_IP_ADDRESS(3),
25 + REMOTE_INTERFACE_IP_ADDRESS(4),
26 + TRAFFIC_ENGINEERING_METRIC(5),
27 + MAXIMUM_BANDWIDTH(6),
28 + MAXIMUM_RESERVABLE_BANDWIDTH(7),
29 + UNRESERVED_BANDWIDTH(8),
30 + ADMINISTRATIVE_GROUP(9);
31 +
32 + private int value;
33 +
34 + /**
35 + * Creates an instance of link sub types.
36 + *
37 + * @param value link sub type value
38 + */
39 + LinkSubTypes(int value) {
40 + this.value = value;
41 + }
42 +
43 + /**
44 + * Gets the link sub type value.
45 + *
46 + * @return link sub type value
47 + */
48 + public int value() {
49 + return value;
50 + }
51 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.exceptions.OspfErrorType;
22 +import org.onosproject.ospf.exceptions.OspfParseException;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +import org.onosproject.ospf.protocol.util.OspfUtil;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +/**
29 + * Representation of link type TE value.
30 + */
31 +public class LinkType extends TlvHeader implements LinkSubType {
32 + private static final Logger log =
33 + LoggerFactory.getLogger(LinkType.class);
34 + private int linkType;
35 +
36 + /**
37 + * Creates link type instance .
38 + */
39 + public LinkType() {
40 +
41 + }
42 +
43 + /**
44 + * Creates link type instance.
45 + *
46 + * @param header tlv header instance
47 + */
48 + public LinkType(TlvHeader header) {
49 + this.setTlvType(header.tlvType());
50 + this.setTlvLength(header.tlvLength());
51 + }
52 +
53 + /**
54 + * Sets link type.
55 + *
56 + * @param linkType value of link type
57 + */
58 + public void setLinkType(int linkType) {
59 + this.linkType = linkType;
60 + }
61 +
62 + /**
63 + * Reads from channel buffer.
64 + *
65 + * @param channelBuffer channel buffer instance
66 + * @throws Exception might throws exception while parsing buffer
67 + */
68 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
69 + try {
70 + int len = channelBuffer.readableBytes();
71 + byte[] tempByteArray = new byte[len];
72 + channelBuffer.readBytes(tempByteArray, 0, len);
73 + this.setLinkType(OspfUtil.byteToInteger(tempByteArray));
74 + } catch (Exception e) {
75 + log.debug("Error::LinkType:: {}", e.getMessage());
76 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
77 + OspfErrorType.BAD_MESSAGE);
78 + }
79 + }
80 +
81 + /**
82 + * Gets link subtype as byte array.
83 + *
84 + * @return byte array of link subtype
85 + */
86 + public byte[] asBytes() {
87 + byte[] linkSubType = null;
88 +
89 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
90 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
91 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
92 + return linkSubType;
93 + }
94 +
95 + /**
96 + * Gets link subtype as bytes.
97 + *
98 + * @return byte array of link subtype
99 + */
100 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
101 + byte[] linkSubTypeBody = new byte[4];
102 + linkSubTypeBody[0] = (byte) this.linkType;
103 + linkSubTypeBody[1] = 0;
104 + linkSubTypeBody[2] = 0;
105 + linkSubTypeBody[3] = 0;
106 + return linkSubTypeBody;
107 + }
108 +
109 + @Override
110 + public String toString() {
111 + return MoreObjects.toStringHelper(getClass())
112 + .add("linkType", linkType)
113 + .toString();
114 + }
115 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.exceptions.OspfErrorType;
22 +import org.onosproject.ospf.exceptions.OspfParseException;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +import org.onosproject.ospf.protocol.util.OspfUtil;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +import java.net.InetAddress;
29 +import java.util.ArrayList;
30 +import java.util.List;
31 +
32 +/**
33 + * Representation of local interface ip address TE value.
34 + */
35 +public class LocalInterfaceIpAddress extends TlvHeader implements LinkSubType {
36 + private static final Logger log =
37 + LoggerFactory.getLogger(RemoteInterfaceIpAddress.class);
38 + private List<String> localInterfaceIPAddress = new ArrayList<>();
39 +
40 + /**
41 + * Creates an instance of local interface ip address.
42 + *
43 + * @param header tlv header instance
44 + */
45 + public LocalInterfaceIpAddress(TlvHeader header) {
46 + this.setTlvType(header.tlvType());
47 + this.setTlvLength(header.tlvLength());
48 + }
49 +
50 + /**
51 + * Adds local interface ip address.
52 + *
53 + * @param localAddress ip address
54 + */
55 + public void addLocalInterfaceIPAddress(String localAddress) {
56 + localInterfaceIPAddress.add(localAddress);
57 + }
58 +
59 + /**
60 + * Gets local interface ip address.
61 + *
62 + * @return localAddress ip address
63 + */
64 + public List<String> getLocalInterfaceIPAddress() {
65 + return localInterfaceIPAddress;
66 + }
67 +
68 + /**
69 + * Reads bytes from channel buffer.
70 + *
71 + * @param channelBuffer channel buffer instance
72 + * @throws Exception might throws exception while parsing buffer
73 + */
74 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
75 + while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
76 + try {
77 + byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
78 + channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
79 + this.addLocalInterfaceIPAddress(InetAddress.getByAddress(tempByteArray).getHostName());
80 + } catch (Exception e) {
81 + log.debug("Error::readFrom:: {}", e.getMessage());
82 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
83 + OspfErrorType.BAD_MESSAGE);
84 + }
85 + }
86 + }
87 +
88 + /**
89 + * Gets local interface ip address as byte array.
90 + *
91 + * @return local interface ip address as byte array
92 + * @throws Exception might throws exception while parsing packet
93 + */
94 + public byte[] asBytes() throws Exception {
95 + byte[] linkSubType = null;
96 +
97 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
98 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
99 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
100 +
101 + return linkSubType;
102 + }
103 +
104 + /**
105 + * Gets byte array of local interface ip address.
106 + *
107 + * @return byte array of local interface ip address
108 + * @throws Exception might throws exception while parsing packet
109 + */
110 + public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
111 +
112 + List<Byte> linkSubTypeBody = new ArrayList<>();
113 +
114 + for (String remoteAddress : this.localInterfaceIPAddress) {
115 + try {
116 + linkSubTypeBody.addAll(Bytes.asList(InetAddress.getByName(remoteAddress).getAddress()));
117 + } catch (Exception e) {
118 + log.debug("Error::getLinkSubTypeTlvBodyAsByteArray:: {}", e.getMessage());
119 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
120 + OspfErrorType.BAD_MESSAGE);
121 + }
122 + }
123 +
124 + return Bytes.toArray(linkSubTypeBody);
125 + }
126 +
127 + @Override
128 + public String toString() {
129 + return MoreObjects.toStringHelper(getClass())
130 + .omitNullValues()
131 + .add("localInterfaceIPAddress", localInterfaceIPAddress)
132 + .toString();
133 + }
134 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.util.OspfUtil;
23 +
24 +/**
25 + * Representation of maximum bandwidth TE value.
26 + */
27 +public class MaximumBandwidth extends TlvHeader implements LinkSubType {
28 + private float maximumBandwidth;
29 +
30 + /**
31 + * Creates an instance of maximum bandwidth.
32 + *
33 + * @param header tlv header instance
34 + */
35 + public MaximumBandwidth(TlvHeader header) {
36 + this.setTlvType(header.tlvType());
37 + this.setTlvLength(header.tlvLength());
38 + }
39 +
40 + /**
41 + * Sets value of maximum bandwidth.
42 + *
43 + * @param maximumBandwidth value of maximum bandwidth
44 + */
45 + public void setMaximumBandwidth(float maximumBandwidth) {
46 + this.maximumBandwidth = maximumBandwidth;
47 + }
48 +
49 + /**
50 + * Gets value of maximum bandwidth.
51 + *
52 + * @return maximumBandwidth value of maximum bandwidth
53 + */
54 + public float getMaximumBandwidthValue() {
55 + return this.maximumBandwidth;
56 + }
57 +
58 + /**
59 + * Reads bytes from channel buffer.
60 + *
61 + * @param channelBuffer channel buffer instance
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) {
64 + byte[] tempByteArray = new byte[tlvLength()];
65 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 + int maxBandwidth = (OspfUtil.byteToInteger(tempByteArray));
67 + this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
68 + }
69 +
70 + /**
71 + * Gets byte array of maximum bandwidth sub tlv.
72 + *
73 + * @return byte array of maximum bandwidth sub tlv
74 + */
75 + public byte[] asBytes() {
76 + byte[] linkSubType = null;
77 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
78 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
79 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
80 +
81 + return linkSubType;
82 + }
83 +
84 + /**
85 + * Gets maximum bandwidth sub tlv byte array.
86 + *
87 + * @return byte array of maximum bandwidth sub tlv
88 + */
89 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
90 + byte[] linkSubTypeBody;
91 + linkSubTypeBody = OspfUtil.convertToFourBytes(Float.floatToIntBits(this.maximumBandwidth));
92 + return linkSubTypeBody;
93 + }
94 +
95 + public String toString() {
96 + return MoreObjects.toStringHelper(getClass())
97 + .add("maximumBandwidth", maximumBandwidth)
98 + .toString();
99 + }
100 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.util.OspfUtil;
23 +
24 +/**
25 + * Representation of maximum reservable bandwidth TE value.
26 + */
27 +public class MaximumReservableBandwidth extends TlvHeader implements LinkSubType {
28 + private float maximumReservableBandwidth;
29 +
30 + /**
31 + * Creates an instance of maximum reservable bandwidth.
32 + *
33 + * @param header tlv header
34 + */
35 + public MaximumReservableBandwidth(TlvHeader header) {
36 + this.setTlvType(header.tlvType());
37 + this.setTlvLength(header.tlvLength());
38 + }
39 +
40 + /**
41 + * Sets value of maximum reversible bandwidth.
42 + *
43 + * @param maximumBandwidth maximum reversible bandwidth
44 + */
45 + public void setMaximumBandwidth(float maximumBandwidth) {
46 + this.maximumReservableBandwidth = maximumBandwidth;
47 + }
48 +
49 + /**
50 + * Gets value of maximum reversible bandwidth.
51 + *
52 + * @return maximumBandwidth maximum reversible bandwidth
53 + */
54 + public float getMaximumBandwidthValue() {
55 + return this.maximumReservableBandwidth;
56 + }
57 +
58 + /**
59 + * Reads bytes from channel buffer.
60 + *
61 + * @param channelBuffer channel buffer instance
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) {
64 + byte[] tempByteArray = new byte[tlvLength()];
65 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 + int maxBandwidth = (OspfUtil.byteToInteger(tempByteArray));
67 + this.setMaximumBandwidth(Float.intBitsToFloat(maxBandwidth));
68 + }
69 +
70 + /**
71 + * Returns byte array of maximum reservable bandwidth.
72 + *
73 + * @return byte array of maximum reservable bandwidth
74 + */
75 + public byte[] asBytes() {
76 + byte[] linkSubType = null;
77 +
78 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
79 + byte[] linkSubTlvBody = getLinksubTypeTlvBodyAsByteArray();
80 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
81 + return linkSubType;
82 +
83 + }
84 +
85 + /**
86 + * Gets maximum reservable bandwidth sub tlv body as byte array.
87 + *
88 + * @return byte of maximum reservable bandwidth sub tlv body
89 + */
90 + public byte[] getLinksubTypeTlvBodyAsByteArray() {
91 + byte[] linkSubTypeBody;
92 + linkSubTypeBody = OspfUtil.convertToFourBytes(Float.floatToIntBits(this.maximumReservableBandwidth));
93 + return linkSubTypeBody;
94 + }
95 +
96 + @Override
97 + public String toString() {
98 + return MoreObjects.toStringHelper(getClass())
99 + .add("maximumReservableBandwidth", maximumReservableBandwidth)
100 + .toString();
101 + }
102 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.exceptions.OspfErrorType;
22 +import org.onosproject.ospf.exceptions.OspfParseException;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +import org.onosproject.ospf.protocol.util.OspfUtil;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +import java.net.InetAddress;
29 +import java.util.ArrayList;
30 +import java.util.List;
31 +
32 +/**
33 + * Representation of remote interface ip address TE value.
34 + */
35 +public class RemoteInterfaceIpAddress extends TlvHeader implements LinkSubType {
36 + private static final Logger log =
37 + LoggerFactory.getLogger(RemoteInterfaceIpAddress.class);
38 + private List<String> remoteInterfaceAddress = new ArrayList<>();
39 +
40 + /**
41 + * Creates an instance of remote interface ip address.
42 + *
43 + * @param header tlv header instance
44 + */
45 + public RemoteInterfaceIpAddress(TlvHeader header) {
46 + this.setTlvType(header.tlvType());
47 + this.setTlvLength(header.tlvLength());
48 + }
49 +
50 + /**
51 + * Adds remote interface ip address.
52 + *
53 + * @param remoteAddress ip address
54 + */
55 + public void addRemoteInterfaceAddress(String remoteAddress) {
56 + remoteInterfaceAddress.add(remoteAddress);
57 + }
58 +
59 + /**
60 + * Gets remote interface ip address.
61 + *
62 + * @return remoteAddress ip address
63 + */
64 + public List<String> getRemoteInterfaceAddress() {
65 + return remoteInterfaceAddress;
66 + }
67 +
68 + /**
69 + * Reads bytes from channel buffer .
70 + *
71 + * @param channelBuffer channel buffer instance
72 + * @throws Exception might throws exception while parsing packet
73 + */
74 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
75 + while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
76 + try {
77 + byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
78 + channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
79 + this.addRemoteInterfaceAddress(InetAddress.getByAddress(tempByteArray).getHostName());
80 + } catch (Exception e) {
81 + log.debug("Error::RemoteInterfaceIPAddress:: {}", e.getMessage());
82 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
83 + OspfErrorType.BAD_MESSAGE);
84 + }
85 + }
86 + }
87 +
88 + /**
89 + * Gets byte array of remote interface ip address .
90 + *
91 + * @return byte array of remote interface ip address
92 + * @throws Exception might throws exception while parsing packet
93 + */
94 + public byte[] asBytes() throws Exception {
95 + byte[] linkSubType = null;
96 +
97 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
98 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
99 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
100 +
101 + return linkSubType;
102 + }
103 +
104 + /**
105 + * Gets byte array of remote interface ip address.
106 + *
107 + * @return byte array of remote interface ip address
108 + * @throws Exception might throws exception while parsing packet
109 + */
110 + public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
111 + List<Byte> linkSubTypeBody = new ArrayList<>();
112 +
113 + for (String remoteAddress : this.remoteInterfaceAddress) {
114 + try {
115 + linkSubTypeBody.addAll(Bytes.asList(InetAddress.getByName(remoteAddress).getAddress()));
116 + } catch (Exception e) {
117 + log.debug("Error::RemoteInterfaceIPAddress:: {}", e.getMessage());
118 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
119 + OspfErrorType.BAD_MESSAGE);
120 + }
121 + }
122 +
123 + return Bytes.toArray(linkSubTypeBody);
124 + }
125 +
126 + /**
127 + * Returns instance as string.
128 + *
129 + * @return instance as string
130 + */
131 + public String toString() {
132 + return MoreObjects.toStringHelper(getClass())
133 + .add("RemoteInterfaceIPAddress", remoteInterfaceAddress)
134 + .toString();
135 + }
136 +
137 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.util.OspfUtil;
23 +
24 +/**
25 + * Representation of traffic engineering metric TE value.
26 + */
27 +public class TrafficEngineeringMetric extends TlvHeader implements LinkSubType {
28 + private long trafficEngineeringMetric;
29 +
30 + /**
31 + * Creates an instance of traffic engineering metric .
32 + *
33 + * @param header tlv header instance
34 + */
35 + public TrafficEngineeringMetric(TlvHeader header) {
36 + this.setTlvType(header.tlvType());
37 + this.setTlvLength(header.tlvLength());
38 + }
39 +
40 + /**
41 + * Sets TE metric value.
42 + *
43 + * @param trafficEngineeringMetric value of trafficEngineeringMetric
44 + */
45 + public void setTrafficEngineeringMetric(long trafficEngineeringMetric) {
46 + this.trafficEngineeringMetric = trafficEngineeringMetric;
47 + }
48 +
49 + /**
50 + * Gets TE metric value.
51 + *
52 + * @return value of traffic engineering metric
53 + */
54 + public long getTrafficEngineeringMetricValue() {
55 + return this.trafficEngineeringMetric;
56 + }
57 +
58 + /**
59 + * Reads bytes from channel buffer .
60 + *
61 + * @param channelBuffer channel buffer instance
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) {
64 + byte[] tempByteArray = new byte[tlvLength()];
65 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 + this.setTrafficEngineeringMetric(OspfUtil.byteToLong(tempByteArray));
67 + }
68 +
69 + /**
70 + * Gets instance as byte array.
71 + *
72 + * @return instance as byte array
73 + */
74 + public byte[] asBytes() {
75 + byte[] linkSubType = null;
76 +
77 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
78 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
79 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
80 +
81 + return linkSubType;
82 + }
83 +
84 + /**
85 + * Gets trafficEngineeringMetric as byte array .
86 + *
87 + * @return byte array of trafficEngineeringMetric
88 + */
89 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
90 +
91 + byte[] linkSubTypeBody;
92 + linkSubTypeBody = OspfUtil.convertToFourBytes(this.trafficEngineeringMetric);
93 +
94 + return linkSubTypeBody;
95 + }
96 +
97 + @Override
98 + public String toString() {
99 + return MoreObjects.toStringHelper(getClass())
100 + .omitNullValues()
101 + .add("trafficEngineeringMetric", trafficEngineeringMetric)
102 + .toString();
103 + }
104 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +
23 +/**
24 + * Representation of an unknown or experimental TE value.
25 + */
26 +public class UnknownLinkSubType extends TlvHeader implements LinkSubType {
27 +
28 + private byte[] value;
29 +
30 + /**
31 + * Creates an instance of this.
32 + *
33 + * @param header tlv header
34 + */
35 + public UnknownLinkSubType(TlvHeader header) {
36 + this.setTlvType(header.tlvType());
37 + this.setTlvLength(header.tlvLength());
38 + }
39 +
40 + /**
41 + * Gets the unknown subtype value .
42 + *
43 + * @return unknown subtype value
44 + */
45 + public byte[] value() {
46 + return value;
47 + }
48 +
49 + /**
50 + * Sets unknown subtype value.
51 + *
52 + * @param value unknown subtype value.
53 + */
54 + public void setValue(byte[] value) {
55 + this.value = value;
56 + }
57 +
58 + /**
59 + * Reads bytes from channel buffer .
60 + *
61 + * @param channelBuffer channel buffer instance
62 + */
63 + public void readFrom(ChannelBuffer channelBuffer) {
64 + byte[] tempByteArray = new byte[tlvLength()];
65 + channelBuffer.readBytes(tempByteArray, 0, tlvLength());
66 + this.setValue(tempByteArray);
67 + }
68 +
69 + /**
70 + * Returns instance as byte array.
71 + *
72 + * @return instance as byte array
73 + */
74 + public byte[] asBytes() {
75 + byte[] linkSubType = null;
76 +
77 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
78 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
79 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
80 + return linkSubType;
81 +
82 + }
83 +
84 + /**
85 + * Gets instance body as byte array.
86 + *
87 + * @return instance body as byte array
88 + */
89 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
90 + return value;
91 + }
92 +
93 + @Override
94 + public String toString() {
95 + return MoreObjects.toStringHelper(getClass())
96 + .omitNullValues()
97 + .add("value", value)
98 + .toString();
99 + }
100 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.util.OspfParameters;
23 +import org.onosproject.ospf.protocol.util.OspfUtil;
24 +
25 +import java.util.ArrayList;
26 +import java.util.List;
27 +
28 +/**
29 + * Representation of an unreserved band width TE value.
30 + */
31 +public class UnreservedBandwidth extends TlvHeader implements LinkSubType {
32 + private List<Float> unReservedBandwidth = new ArrayList<>();
33 +
34 + /**
35 + * Creates an instance of unreserved band width.
36 + *
37 + * @param header tlv header instance
38 + */
39 + public UnreservedBandwidth(TlvHeader header) {
40 + this.setTlvType(header.tlvType());
41 + this.setTlvLength(header.tlvLength());
42 + }
43 +
44 + /**
45 + * Adds value of un reserved bandwidth .
46 + *
47 + * @param unreservedBandwidth value of un reserved bandwidth
48 + */
49 + public void addUnReservedBandwidth(float unreservedBandwidth) {
50 + this.unReservedBandwidth.add(unreservedBandwidth);
51 + }
52 +
53 + /**
54 + * Gets list of un reserved bandwidth .
55 + *
56 + * @return List of un reserved bandwidth
57 + */
58 + public List<Float> getUnReservedBandwidthValue() {
59 + return this.unReservedBandwidth;
60 + }
61 +
62 + /**
63 + * Reads bytes from channel buffer .
64 + *
65 + * @param channelBuffer channel buffer instance
66 + */
67 + public void readFrom(ChannelBuffer channelBuffer) {
68 + while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
69 + int maxReversibleBandwidth = channelBuffer.readInt();
70 + this.addUnReservedBandwidth(Float.intBitsToFloat(maxReversibleBandwidth));
71 + }
72 + }
73 +
74 + /**
75 + * Gets instance as byte array.
76 + *
77 + * @return instance as byte array
78 + */
79 + public byte[] asBytes() {
80 + byte[] linkSubType = null;
81 +
82 + byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
83 + byte[] linkSubTlvBody = getLinkSubTypeTlvBodyAsByteArray();
84 + linkSubType = Bytes.concat(linkSubTlvHeader, linkSubTlvBody);
85 +
86 + return linkSubType;
87 + }
88 +
89 + /**
90 + * Gets unreserved bandwidth as byte array.
91 + *
92 + * @return unreserved bandwidth as byte array
93 + */
94 + public byte[] getLinkSubTypeTlvBodyAsByteArray() {
95 + List<Byte> linkSubTypeBody = new ArrayList<>();
96 + if (this.unReservedBandwidth.size() < 8) {
97 + int size = OspfUtil.EIGHT_BYTES - this.unReservedBandwidth.size();
98 + for (int i = 0; i < size; i++) {
99 + linkSubTypeBody.addAll(Bytes.asList(OspfUtil.convertToFourBytes(OspfParameters.INITIAL_BANDWIDTH)));
100 + }
101 + }
102 + for (Float unreservedBandwidth : this.unReservedBandwidth) {
103 + int unresBandwidth = Float.floatToIntBits(unreservedBandwidth);
104 + linkSubTypeBody.addAll(Bytes.asList(OspfUtil.convertToFourBytes(unresBandwidth)));
105 + }
106 +
107 + return Bytes.toArray(linkSubTypeBody);
108 + }
109 +
110 + @Override
111 + public String toString() {
112 + return MoreObjects.toStringHelper(getClass())
113 + .omitNullValues()
114 + .add("unReservedBandwidth", unReservedBandwidth)
115 + .toString();
116 + }
117 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Implementation of the ospf TE link types.
19 + */
20 +package org.onosproject.ospf.protocol.lsa.linksubtype;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
22 +import org.onosproject.ospf.protocol.lsa.linksubtype.AdministrativeGroup;
23 +import org.onosproject.ospf.protocol.lsa.linksubtype.LinkId;
24 +import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubType;
25 +import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubTypes;
26 +import org.onosproject.ospf.protocol.lsa.linksubtype.LinkType;
27 +import org.onosproject.ospf.protocol.lsa.linksubtype.LocalInterfaceIpAddress;
28 +import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumBandwidth;
29 +import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumReservableBandwidth;
30 +import org.onosproject.ospf.protocol.lsa.linksubtype.RemoteInterfaceIpAddress;
31 +import org.onosproject.ospf.protocol.lsa.linksubtype.TrafficEngineeringMetric;
32 +import org.onosproject.ospf.protocol.lsa.linksubtype.UnknownLinkSubType;
33 +import org.onosproject.ospf.protocol.lsa.linksubtype.UnreservedBandwidth;
34 +import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
35 +import org.onosproject.ospf.protocol.util.OspfUtil;
36 +
37 +import java.util.ArrayList;
38 +import java.util.List;
39 +
40 +/**
41 + * Representation of an OSPF Opaque link tlv.
42 + */
43 +public class LinkTlv extends TlvHeader implements TopLevelTlv {
44 + private List<LinkSubType> subTlv = new ArrayList<>();
45 +
46 + /**
47 + * Creates an instance of link tlv.
48 + *
49 + * @param header tlv header
50 + */
51 + public LinkTlv(TlvHeader header) {
52 + this.setTlvType(header.tlvType());
53 + this.setTlvLength(header.tlvLength());
54 + }
55 +
56 + /**
57 + * Gets sub tlv lists.
58 + *
59 + * @return sub tlv lists
60 + */
61 + public List<LinkSubType> subTlvList() {
62 + return this.subTlv;
63 + }
64 +
65 + /**
66 + * Reads bytes from channel buffer .
67 + *
68 + * @param channelBuffer channel buffer instance
69 + * @throws Exception might throws exception while parsing packet
70 + */
71 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
72 + while (channelBuffer.readableBytes() > 0) {
73 + TlvHeader tlvHeader = new TlvHeader();
74 + tlvHeader.setTlvType(channelBuffer.readUnsignedShort());
75 + tlvHeader.setTlvLength(channelBuffer.readUnsignedShort());
76 +
77 + if (LinkSubTypes.LINK_TYPE.value() == tlvHeader.tlvType()) {
78 + LinkType linktype = new LinkType(tlvHeader);
79 + linktype.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
80 + subTlv.add(linktype);
81 + if (tlvHeader.tlvLength() < OspfUtil.FOUR_BYTES) {
82 + int readerIndex = channelBuffer.readerIndex() + (OspfUtil.FOUR_BYTES - tlvHeader.tlvLength());
83 + channelBuffer.readerIndex(readerIndex);
84 + }
85 + } else if (LinkSubTypes.LINK_ID.value() == tlvHeader.tlvType()) {
86 + LinkId linkId = new LinkId(tlvHeader);
87 + linkId.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
88 + subTlv.add(linkId);
89 + } else if (LinkSubTypes.LOCAL_INTERFACE_IP_ADDRESS.value() == tlvHeader.tlvType()) {
90 + LocalInterfaceIpAddress localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
91 + localInterfaceIpAddress.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
92 + subTlv.add(localInterfaceIpAddress);
93 + } else if (LinkSubTypes.REMOTE_INTERFACE_IP_ADDRESS.value() == tlvHeader.tlvType()) {
94 + RemoteInterfaceIpAddress remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
95 + remoteInterfaceIpAddress.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
96 + subTlv.add(remoteInterfaceIpAddress);
97 + } else if (LinkSubTypes.TRAFFIC_ENGINEERING_METRIC.value() == tlvHeader.tlvType()) {
98 + TrafficEngineeringMetric trafficEngineeringMetric = new TrafficEngineeringMetric(tlvHeader);
99 + trafficEngineeringMetric.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
100 + subTlv.add(trafficEngineeringMetric);
101 + } else if (LinkSubTypes.MAXIMUM_BANDWIDTH.value() == tlvHeader.tlvType()) {
102 + MaximumBandwidth maximumBandwidth = new MaximumBandwidth(tlvHeader);
103 + maximumBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
104 + subTlv.add(maximumBandwidth);
105 + } else if (LinkSubTypes.MAXIMUM_RESERVABLE_BANDWIDTH.value() == tlvHeader.tlvType()) {
106 + MaximumReservableBandwidth maximumReservableBandwidth = new MaximumReservableBandwidth(tlvHeader);
107 + maximumReservableBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
108 + subTlv.add(maximumReservableBandwidth);
109 + } else if (LinkSubTypes.UNRESERVED_BANDWIDTH.value() == tlvHeader.tlvType()) {
110 + UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth(tlvHeader);
111 + unreservedBandwidth.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
112 + subTlv.add(unreservedBandwidth);
113 + } else if (LinkSubTypes.ADMINISTRATIVE_GROUP.value() == tlvHeader.tlvType()) {
114 + AdministrativeGroup administrativeGroup = new AdministrativeGroup(tlvHeader);
115 + administrativeGroup.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
116 + subTlv.add(administrativeGroup);
117 + } else {
118 + UnknownLinkSubType unknownLinkSubType = new UnknownLinkSubType(tlvHeader);
119 + unknownLinkSubType.readFrom(channelBuffer.readBytes(tlvHeader.tlvLength()));
120 + subTlv.add(unknownLinkSubType);
121 + }
122 + }
123 + }
124 +
125 + /**
126 + * Gets link tlv as byte array.
127 + *
128 + * @return link tlv as byte array
129 + * @throws Exception might throws exception while parsing buffer
130 + */
131 + public byte[] asBytes() throws Exception {
132 + byte[] lsaMessage = null;
133 +
134 + byte[] tlvHeader = getTlvHeaderAsByteArray();
135 + byte[] tlvBody = getTlvBodyAsByteArray();
136 + lsaMessage = Bytes.concat(tlvHeader, tlvBody);
137 +
138 + return lsaMessage;
139 + }
140 +
141 + /**
142 + * Gets tlv body as byte array.
143 + *
144 + * @return tlv body as byte array
145 + * @throws Exception might throws exception while parsing buffer
146 + */
147 + public byte[] getTlvBodyAsByteArray() throws Exception {
148 +
149 + List<Byte> bodyLst = new ArrayList<>();
150 + for (LinkSubType tlv : subTlv) {
151 + //Check the type of tlv and build bytes accordingly
152 + if (tlv instanceof LinkType) {
153 + LinkType linkType = (LinkType) tlv;
154 + bodyLst.addAll(Bytes.asList(linkType.asBytes()));
155 + } else if (tlv instanceof LinkId) {
156 + LinkId linkId = (LinkId) tlv;
157 + bodyLst.addAll(Bytes.asList(linkId.asBytes()));
158 + } else if (tlv instanceof LocalInterfaceIpAddress) {
159 + LocalInterfaceIpAddress localInterfaceIpAddress = (LocalInterfaceIpAddress) tlv;
160 + bodyLst.addAll(Bytes.asList(localInterfaceIpAddress.asBytes()));
161 + } else if (tlv instanceof RemoteInterfaceIpAddress) {
162 + RemoteInterfaceIpAddress remoteInterfaceIpAddress = (RemoteInterfaceIpAddress) tlv;
163 + bodyLst.addAll(Bytes.asList(remoteInterfaceIpAddress.asBytes()));
164 + } else if (tlv instanceof TrafficEngineeringMetric) {
165 + TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) tlv;
166 + bodyLst.addAll(Bytes.asList(trafficEngineeringMetric.asBytes()));
167 + } else if (tlv instanceof MaximumBandwidth) {
168 + MaximumBandwidth maximumBandwidth = (MaximumBandwidth) tlv;
169 + bodyLst.addAll(Bytes.asList(maximumBandwidth.asBytes()));
170 + } else if (tlv instanceof MaximumReservableBandwidth) {
171 + MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) tlv;
172 + bodyLst.addAll(Bytes.asList(maximumReservableBandwidth.asBytes()));
173 + } else if (tlv instanceof UnreservedBandwidth) {
174 + UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) tlv;
175 + bodyLst.addAll(Bytes.asList(unreservedBandwidth.asBytes()));
176 + } else if (tlv instanceof AdministrativeGroup) {
177 + AdministrativeGroup administrativeGroup = (AdministrativeGroup) tlv;
178 + bodyLst.addAll(Bytes.asList(administrativeGroup.asBytes()));
179 + } else {
180 + UnknownLinkSubType unknownLinkSubType = (UnknownLinkSubType) tlv;
181 + bodyLst.addAll(Bytes.asList(unknownLinkSubType.asBytes()));
182 + }
183 + }
184 + return Bytes.toArray(bodyLst);
185 + }
186 +
187 + @Override
188 + public String toString() {
189 + return MoreObjects.toStringHelper(getClass())
190 + .omitNullValues()
191 + .add("subTlv", subTlv)
192 + .toString();
193 + }
194 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
17 +
18 +/**
19 + * Representation of an OSPF Opaque top level tlv types.
20 + */
21 +public enum OpaqueTopLevelTlvTypes {
22 +
23 + ROUTER(1),
24 + LINK(2);
25 +
26 + private int value;
27 +
28 + /**
29 + * Creates an instance of Opaque top level tlv types.
30 + *
31 + * @param value
32 + */
33 + OpaqueTopLevelTlvTypes(int value) {
34 + this.value = value;
35 + }
36 +
37 + /**
38 + * Gets the tlv type value.
39 + *
40 + * @return tlv type value
41 + */
42 + public int value() {
43 + return value;
44 + }
45 +
46 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.primitives.Bytes;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onosproject.ospf.exceptions.OspfErrorType;
23 +import org.onosproject.ospf.exceptions.OspfParseException;
24 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
25 +import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
26 +import org.onosproject.ospf.protocol.util.OspfUtil;
27 +import org.slf4j.Logger;
28 +import org.slf4j.LoggerFactory;
29 +
30 +import java.util.ArrayList;
31 +import java.util.List;
32 +
33 +/**
34 + * Representation of an OSPF Opaque router tlv.
35 + */
36 +public class RouterTlv extends TlvHeader implements TopLevelTlv {
37 +
38 + private static final Logger log =
39 + LoggerFactory.getLogger(RouterTlv.class);
40 + private Ip4Address routerAddress;
41 +
42 + /**
43 + * Creates an instance of Opaque router tlv.
44 + *
45 + * @param header tlv header
46 + */
47 + public RouterTlv(TlvHeader header) {
48 + this.setTlvType(header.tlvType());
49 + this.setTlvLength(header.tlvLength());
50 + }
51 +
52 + /**
53 + * Gets router address.
54 + *
55 + * @return router address
56 + */
57 + public Ip4Address routerAddress() {
58 + return routerAddress;
59 + }
60 +
61 + /**
62 + * Sets router address.
63 + *
64 + * @param routerAddress router address.
65 + */
66 + public void setRouterAddress(Ip4Address routerAddress) {
67 + this.routerAddress = routerAddress;
68 + }
69 +
70 + /**
71 + * Reads bytes from channel buffer .
72 + *
73 + * @param channelBuffer channel buffer instance
74 + * @throws Exception might throws exception while parsing buffer
75 + */
76 + public void readFrom(ChannelBuffer channelBuffer) throws Exception {
77 + try {
78 + byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
79 + channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
80 + this.setRouterAddress(Ip4Address.valueOf(tempByteArray));
81 + } catch (Exception e) {
82 + log.debug("Error::RouterTLV:: {}", e.getMessage());
83 + throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
84 + OspfErrorType.BAD_MESSAGE);
85 + }
86 + }
87 +
88 + /**
89 + * Gets router tlv as byte array.
90 + *
91 + * @return router tlv as byte array
92 + */
93 + public byte[] asBytes() {
94 + byte[] lsaMessage = null;
95 +
96 + byte[] tlvHeader = getTlvHeaderAsByteArray();
97 + byte[] tlvBody = getTlvBodyAsByteArray();
98 + lsaMessage = Bytes.concat(tlvHeader, tlvBody);
99 +
100 + return lsaMessage;
101 + }
102 +
103 + /**
104 + * Gets tlv body as byte array.
105 + *
106 + * @return tlv body as byte array
107 + */
108 + public byte[] getTlvBodyAsByteArray() {
109 + List<Byte> bodyLst = new ArrayList<>();
110 + bodyLst.addAll(Bytes.asList(this.routerAddress().toOctets()));
111 +
112 + return Bytes.toArray(bodyLst);
113 + }
114 +
115 + @Override
116 + public String toString() {
117 + return MoreObjects.toStringHelper(getClass())
118 + .omitNullValues()
119 + .add("routerAddress", routerAddress)
120 + .toString();
121 + }
122 +}
123 +
124 +
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Implementation of the OSPF Opaque Tlv Types.
19 + */
20 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +
22 +import static org.hamcrest.CoreMatchers.notNullValue;
23 +import static org.hamcrest.Matchers.is;
24 +import static org.junit.Assert.assertThat;
25 +
26 +/**
27 + * Unit test class for Tlv Header.
28 + */
29 +public class TlvHeaderTest {
30 +
31 + private TlvHeader tlvHeader;
32 + private byte[] result;
33 +
34 +
35 + @Before
36 + public void setUp() throws Exception {
37 + tlvHeader = new TlvHeader();
38 + }
39 +
40 + @After
41 + public void tearDown() throws Exception {
42 + tlvHeader = null;
43 + result = null;
44 + }
45 +
46 + /**
47 + * Tests to string method.
48 + */
49 + @Test
50 + public void testToString() throws Exception {
51 + assertThat(tlvHeader.toString(), is(notNullValue()));
52 + }
53 +
54 + /**
55 + * Tests tlvLength() getter method.
56 + */
57 + @Test
58 + public void testGetTlvLength() throws Exception {
59 + tlvHeader.setTlvLength(2);
60 + assertThat(tlvHeader.tlvLength(), is(2));
61 + }
62 +
63 + /**
64 + * Tests tlvLength() setter method.
65 + */
66 + @Test
67 + public void testSetTlvLength() throws Exception {
68 + tlvHeader.setTlvLength(2);
69 + assertThat(tlvHeader.tlvLength(), is(2));
70 + }
71 +
72 + /**
73 + * Tests tlvType() getter method.
74 + */
75 + @Test
76 + public void testGetTlvType() throws Exception {
77 + tlvHeader.setTlvType(2);
78 + assertThat(tlvHeader.tlvType(), is(2));
79 + }
80 +
81 + /**
82 + * Tests tlvType() setter method.
83 + */
84 + @Test
85 + public void testSetTlvType() throws Exception {
86 + tlvHeader.setTlvType(2);
87 + assertThat(tlvHeader.tlvType(), is(2));
88 + }
89 +
90 + /**
91 + * Tests getTlvHeaderAsByteArray() method.
92 + */
93 + @Test
94 + public void testGetTlvHeaderAsByteArray() throws Exception {
95 + result = tlvHeader.getTlvHeaderAsByteArray();
96 + assertThat(result, is(notNullValue()));
97 + }
98 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for AdministrativeGroup.
31 + */
32 +public class AdministrativeGroupTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 1};
35 + private AdministrativeGroup administrativeGroup;
36 + private ChannelBuffer channelBuffer;
37 + private TlvHeader tlvHeader;
38 + private byte[] result;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + administrativeGroup = new AdministrativeGroup(new TlvHeader());
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + administrativeGroup = null;
48 + channelBuffer = null;
49 + tlvHeader = null;
50 + }
51 +
52 + /**
53 + * Tests administrativeGroup() getter method.
54 + */
55 + @Test
56 + public void testGetAdministrativeGroup() throws Exception {
57 + administrativeGroup.setAdministrativeGroup(1);
58 + assertThat(administrativeGroup.administrativeGroup(), is(1));
59 + }
60 +
61 + /**
62 + * Tests administrativeGroup() setter method.
63 + */
64 + @Test
65 + public void testSetAdministrativeGroup() throws Exception {
66 + administrativeGroup.setAdministrativeGroup(1);
67 + assertThat(administrativeGroup.administrativeGroup(), is(1));
68 + }
69 +
70 + /**
71 + * Tests readFrom() method.
72 + */
73 + @Test
74 + public void testReadFrom() throws Exception {
75 + tlvHeader = new TlvHeader();
76 + tlvHeader.setTlvType(9);
77 + tlvHeader.setTlvLength(4);
78 + administrativeGroup = new AdministrativeGroup(tlvHeader);
79 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
80 + administrativeGroup.readFrom(channelBuffer);
81 + assertThat(administrativeGroup.administrativeGroup(), is(notNullValue()));
82 + }
83 +
84 + /**
85 + * Tests asBytes() method.
86 + */
87 + @Test
88 + public void testAsBytes() throws Exception {
89 + result = administrativeGroup.asBytes();
90 + assertThat(result, is(notNullValue()));
91 + }
92 +
93 +
94 + /**
95 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
96 + */
97 + @Test
98 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
99 + result = administrativeGroup.getLinkSubTypeTlvBodyAsByteArray();
100 + assertThat(result, is(notNullValue()));
101 + }
102 +
103 + /**
104 + * Tests to string method.
105 + */
106 + @Test
107 + public void testToString() throws Exception {
108 + assertThat(administrativeGroup.toString(), is(notNullValue()));
109 + }
110 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for LinkId.
31 + */
32 +public class LinkIdTest {
33 +
34 + private final byte[] packet = {1, 1, 1, 1};
35 + private final byte[] packet1 = {0, 0, 1};
36 + private LinkId linkId;
37 + private TlvHeader tlvHeader;
38 + private ChannelBuffer channelBuffer;
39 + private byte[] result;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + linkId = new LinkId(new TlvHeader());
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + linkId = null;
49 + channelBuffer = null;
50 + tlvHeader = null;
51 + }
52 +
53 + /**
54 + * Tests to string method.
55 + */
56 + @Test
57 + public void testToString() throws Exception {
58 + assertThat(linkId.toString(), is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests linkId() getter method.
63 + */
64 + @Test
65 + public void testGetLinkId() throws Exception {
66 + linkId.setLinkId("1.1.1.1");
67 + assertThat(linkId, is(notNullValue()));
68 + }
69 +
70 + /**
71 + * Tests linkId() setter method.
72 + */
73 + @Test
74 + public void testSetLinkId() throws Exception {
75 + linkId.setLinkId("1.1.1.1");
76 + assertThat(linkId, is(notNullValue()));
77 + }
78 +
79 + /**
80 + * Tests readFrom() method.
81 + */
82 + @Test
83 + public void testReadFrom() throws Exception {
84 + tlvHeader = new TlvHeader();
85 + tlvHeader.setTlvType(2);
86 + tlvHeader.setTlvLength(4);
87 + linkId = new LinkId(tlvHeader);
88 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
89 + linkId.readFrom(channelBuffer);
90 + assertThat(linkId, is(notNullValue()));
91 + }
92 +
93 + /**
94 + * Tests readFrom() method.
95 + */
96 + @Test(expected = Exception.class)
97 + public void testReadFrom1() throws Exception {
98 + tlvHeader = new TlvHeader();
99 + tlvHeader.setTlvType(2);
100 + tlvHeader.setTlvLength(4);
101 + linkId = new LinkId(tlvHeader);
102 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
103 + linkId.readFrom(channelBuffer);
104 + assertThat(linkId, is(notNullValue()));
105 + }
106 +
107 + /**
108 + * Tests asBytes() method.
109 + */
110 + @Test
111 + public void testAsBytes() throws Exception {
112 + result = linkId.asBytes();
113 + assertThat(result, is(notNullValue()));
114 + }
115 +
116 + /**
117 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
118 + */
119 + @Test
120 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
121 + result = linkId.getLinkSubTypeTlvBodyAsByteArray();
122 + assertThat(result, is(notNullValue()));
123 + }
124 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for LinkType.
31 + */
32 +public class LinkTypeTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 1};
35 + private final byte[] packet1 = {0, 0, 1};
36 + private LinkType linkType;
37 + private byte[] result;
38 + private ChannelBuffer channelBuffer;
39 + private TlvHeader tlvHeader;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + linkType = new LinkType();
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + linkType = null;
49 + channelBuffer = null;
50 + tlvHeader = null;
51 + }
52 +
53 + /**
54 + * Tests to string method.
55 + */
56 + @Test
57 + public void testToString() throws Exception {
58 + assertThat(linkType.toString(), is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests linkType() getter method.
63 + */
64 + @Test
65 + public void testGetLinkType() throws Exception {
66 + linkType.setLinkType(1);
67 + assertThat(linkType, is(notNullValue()));
68 + }
69 +
70 + /**
71 + * Tests linkType() setter method.
72 + */
73 + @Test
74 + public void testSetLinkType() throws Exception {
75 + linkType.setLinkType(1);
76 + assertThat(linkType, is(notNullValue()));
77 + }
78 +
79 + /**
80 + * Tests readFrom() method.
81 + */
82 + @Test
83 + public void testReadFrom() throws Exception {
84 + tlvHeader = new TlvHeader();
85 + tlvHeader.setTlvType(1);
86 + tlvHeader.setTlvLength(4);
87 + linkType = new LinkType(tlvHeader);
88 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
89 + linkType.readFrom(channelBuffer);
90 + assertThat(linkType, is(notNullValue()));
91 + }
92 +
93 + /**
94 + * Tests readFrom() method.
95 + */
96 + @Test
97 + public void testReadFrom1() throws Exception {
98 + tlvHeader = new TlvHeader();
99 + tlvHeader.setTlvType(1);
100 + tlvHeader.setTlvLength(4);
101 + linkType = new LinkType(tlvHeader);
102 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
103 + linkType.readFrom(channelBuffer);
104 + assertThat(linkType, is(notNullValue()));
105 + }
106 +
107 + /**
108 + * Tests asBytes() method.
109 + */
110 + @Test
111 + public void testAsBytes() throws Exception {
112 + result = linkType.asBytes();
113 + assertThat(result, is(notNullValue()));
114 + }
115 +
116 +
117 + /**
118 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
119 + */
120 + @Test
121 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
122 + result = linkType.getLinkSubTypeTlvBodyAsByteArray();
123 + assertThat(result, is(notNullValue()));
124 + }
125 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for LocalInterfaceIpAddress.
31 + */
32 +public class LocalInterfaceIpAddressTest {
33 +
34 + private final byte[] packet = {1, 1, 1, 1};
35 + private final byte[] packet1 = {};
36 + private LocalInterfaceIpAddress localInterfaceIpAddress;
37 + private TlvHeader tlvHeader;
38 + private byte[] result;
39 + private ChannelBuffer channelBuffer;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + localInterfaceIpAddress = new LocalInterfaceIpAddress(new TlvHeader());
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + localInterfaceIpAddress = null;
49 + tlvHeader = null;
50 + result = null;
51 + channelBuffer = null;
52 + }
53 +
54 + /**
55 + * Tests to string method.
56 + */
57 + @Test
58 + public void testToString() throws Exception {
59 + assertThat(localInterfaceIpAddress.toString(), is(notNullValue()));
60 + }
61 +
62 + /**
63 + * Tests addLocalInterfaceIPAddress() method.
64 + */
65 + @Test
66 + public void testAddLocalInterfaceIPAddress() throws Exception {
67 + localInterfaceIpAddress.addLocalInterfaceIPAddress("1.1.1.1");
68 + assertThat(localInterfaceIpAddress, is(notNullValue()));
69 + }
70 +
71 + /**
72 + * Tests readFrom() method.
73 + */
74 + @Test
75 + public void testReadFrom() throws Exception {
76 + tlvHeader = new TlvHeader();
77 + tlvHeader.setTlvType(3);
78 + tlvHeader.setTlvLength(4);
79 + localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
80 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
81 + localInterfaceIpAddress.readFrom(channelBuffer);
82 + assertThat(localInterfaceIpAddress, is(notNullValue()));
83 + }
84 +
85 + /**
86 + * Tests readFrom() method.
87 + */
88 + @Test
89 + public void testReadFrom1() throws Exception {
90 + tlvHeader = new TlvHeader();
91 + tlvHeader.setTlvType(3);
92 + tlvHeader.setTlvLength(4);
93 + localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader);
94 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
95 + localInterfaceIpAddress.readFrom(channelBuffer);
96 + assertThat(localInterfaceIpAddress, is(notNullValue()));
97 + }
98 +
99 + /**
100 + * Tests asBytes() method.
101 + */
102 + @Test
103 + public void testAsBytes() throws Exception {
104 + result = localInterfaceIpAddress.asBytes();
105 + assertThat(result, is(notNullValue()));
106 + }
107 +
108 +
109 + /**
110 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
111 + */
112 + @Test
113 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
114 + result = localInterfaceIpAddress.getLinkSubTypeTlvBodyAsByteArray();
115 + assertThat(result, is(notNullValue()));
116 + }
117 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for MaximumBandwidth.
31 + */
32 +public class MaximumBandwidthTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 0};
35 + private MaximumBandwidth maximumBandwidth;
36 + private TlvHeader header;
37 + private ChannelBuffer channelBuffer;
38 + private byte[] result;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + maximumBandwidth = new MaximumBandwidth(new TlvHeader());
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + maximumBandwidth = null;
48 + header = null;
49 + channelBuffer = null;
50 + result = null;
51 + }
52 +
53 + /**
54 + * Tests maximumBandwidth() setter method.
55 + */
56 + @Test
57 + public void testSetMaximumBandwidth() throws Exception {
58 + maximumBandwidth.setMaximumBandwidth(123456.00f);
59 + assertThat(maximumBandwidth, is(notNullValue()));
60 + }
61 +
62 + /**
63 + * Tests readFrom() method.
64 + */
65 + @Test
66 + public void testReadFrom() throws Exception {
67 + header = new TlvHeader();
68 + header.setTlvType(6);
69 + header.setTlvLength(4);
70 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
71 + maximumBandwidth = new MaximumBandwidth(header);
72 + maximumBandwidth.readFrom(channelBuffer);
73 + assertThat(maximumBandwidth, is(notNullValue()));
74 + }
75 +
76 + /**
77 + * Tests asBytes() method.
78 + */
79 + @Test
80 + public void testAsBytes() throws Exception {
81 + result = maximumBandwidth.asBytes();
82 + assertThat(result, is(notNullValue()));
83 + }
84 +
85 + /**
86 + * Tests to string method.
87 + */
88 + @Test
89 + public void testToString() throws Exception {
90 + assertThat(maximumBandwidth.toString(), is(notNullValue()));
91 + }
92 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for MaximumReservableBandwidth.
31 + */
32 +public class MaximumReservableBandwidthTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 0};
35 + private MaximumReservableBandwidth maximumReservableBandwidth;
36 + private TlvHeader header;
37 + private ChannelBuffer channelBuffer;
38 + private byte[] result;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + maximumReservableBandwidth = new MaximumReservableBandwidth(new TlvHeader());
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + maximumReservableBandwidth = null;
48 + header = null;
49 + channelBuffer = null;
50 + result = null;
51 + }
52 +
53 +
54 + /**
55 + * Tests maximumBandwidth() setter method.
56 + */
57 + @Test
58 + public void testSetMaximumBandwidth() throws Exception {
59 + maximumReservableBandwidth.setMaximumBandwidth(123456.78f);
60 + assertThat(maximumReservableBandwidth, is(notNullValue()));
61 + }
62 +
63 + /**
64 + * Tests readFrom() method.
65 + */
66 + @Test
67 + public void testReadFrom() throws Exception {
68 + header = new TlvHeader();
69 + header.setTlvType(6);
70 + header.setTlvLength(4);
71 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
72 + maximumReservableBandwidth = new MaximumReservableBandwidth(header);
73 + maximumReservableBandwidth.readFrom(channelBuffer);
74 + assertThat(maximumReservableBandwidth, is(notNullValue()));
75 + }
76 +
77 + /**
78 + * Tests asBytes() method.
79 + */
80 + @Test
81 + public void testAsBytes() throws Exception {
82 + result = maximumReservableBandwidth.asBytes();
83 + assertThat(result, is(notNullValue()));
84 + }
85 +
86 +
87 + /**
88 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
89 + */
90 + @Test
91 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
92 + result = maximumReservableBandwidth.getLinksubTypeTlvBodyAsByteArray();
93 + assertThat(result, is(notNullValue()));
94 + }
95 +
96 + /**
97 + * Tests to string method.
98 + */
99 + @Test
100 + public void testToString() throws Exception {
101 + assertThat(maximumReservableBandwidth.toString(), is(notNullValue()));
102 + }
103 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +
30 +/**
31 + * Unit test class for RemoteInterfaceIpAddress.
32 + */
33 +public class RemoteInterfaceIpAddressTest {
34 +
35 + private final byte[] packet = {1, 1, 1, 1};
36 + private final byte[] packet1 = {};
37 + private byte[] result;
38 + private TlvHeader tlvHeader;
39 + private RemoteInterfaceIpAddress remoteInterfaceIpAddress;
40 + private ChannelBuffer channelBuffer;
41 +
42 + @Before
43 + public void setUp() throws Exception {
44 + remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(new TlvHeader());
45 + }
46 +
47 + @After
48 + public void tearDown() throws Exception {
49 + remoteInterfaceIpAddress = null;
50 + result = null;
51 + tlvHeader = null;
52 + channelBuffer = null;
53 + }
54 +
55 + /**
56 + * Tests addRemoteInterfaceAddress() method.
57 + */
58 + @Test
59 + public void testAddRemoteInterfaceIpAddress() throws Exception {
60 + remoteInterfaceIpAddress.addRemoteInterfaceAddress("1.1.1.1");
61 + assertThat(remoteInterfaceIpAddress, is(notNullValue()));
62 + }
63 +
64 +
65 + /**
66 + * Tests readFrom() method.
67 + */
68 + @Test
69 + public void testReadFrom() throws Exception {
70 + tlvHeader = new TlvHeader();
71 + tlvHeader.setTlvType(4);
72 + tlvHeader.setTlvLength(4);
73 + remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
74 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
75 + remoteInterfaceIpAddress.readFrom(channelBuffer);
76 + assertThat(remoteInterfaceIpAddress, is(notNullValue()));
77 + }
78 +
79 + /**
80 + * Tests readFrom() method.
81 + */
82 + @Test
83 + public void testReadFrom1() throws Exception {
84 + tlvHeader = new TlvHeader();
85 + tlvHeader.setTlvType(4);
86 + tlvHeader.setTlvLength(4);
87 + remoteInterfaceIpAddress = new RemoteInterfaceIpAddress(tlvHeader);
88 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
89 + remoteInterfaceIpAddress.readFrom(channelBuffer);
90 + assertThat(remoteInterfaceIpAddress, is(notNullValue()));
91 + }
92 +
93 + /**
94 + * Tests asBytes() method.
95 + */
96 + @Test
97 + public void testAsBytes() throws Exception {
98 + result = remoteInterfaceIpAddress.asBytes();
99 + assertThat(result, is(notNullValue()));
100 + }
101 +
102 +
103 + /**
104 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
105 + */
106 + @Test
107 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
108 + result = remoteInterfaceIpAddress.getLinkSubTypeTlvBodyAsByteArray();
109 + assertThat(result, is(notNullValue()));
110 + }
111 +
112 + /**
113 + * Tests to string method.
114 + */
115 + @Test
116 + public void testToString() throws Exception {
117 + assertThat(remoteInterfaceIpAddress.toString(), is(notNullValue()));
118 + }
119 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.CoreMatchers.is;
26 +import static org.hamcrest.CoreMatchers.notNullValue;
27 +import static org.hamcrest.MatcherAssert.assertThat;
28 +
29 +/**
30 + * Unit test class for TrafficEngineeringMetric.
31 + */
32 +public class TrafficEngineeringMetricTest {
33 +
34 + private final byte[] packet = {0, 0, 1, 1};
35 + private TrafficEngineeringMetric trafficEngineeringMetric;
36 + private TlvHeader header;
37 + private byte[] result;
38 + private ChannelBuffer channelBuffer;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + trafficEngineeringMetric = new TrafficEngineeringMetric(new TlvHeader());
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + trafficEngineeringMetric = null;
48 + header = null;
49 + result = null;
50 + channelBuffer = null;
51 + }
52 +
53 +
54 + /**
55 + * Tests trafficEngineeringMetric() setter method.
56 + */
57 + @Test
58 + public void testSetTrafficEngineeringMetric() throws Exception {
59 + trafficEngineeringMetric.setTrafficEngineeringMetric(123456789L);
60 + assertThat(trafficEngineeringMetric, is(notNullValue()));
61 + }
62 +
63 + /**
64 + * Tests readFrom() method.
65 + */
66 + @Test
67 + public void testReadFrom() throws Exception {
68 + header = new TlvHeader();
69 + header.setTlvLength(4);
70 + header.setTlvType(5);
71 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
72 + trafficEngineeringMetric = new TrafficEngineeringMetric(header);
73 + trafficEngineeringMetric.readFrom(channelBuffer);
74 + assertThat(trafficEngineeringMetric, is(notNullValue()));
75 + }
76 +
77 + /**
78 + * Tests asBytes() method.
79 + */
80 + @Test
81 + public void testAsBytes() throws Exception {
82 + result = trafficEngineeringMetric.asBytes();
83 + assertThat(result, is(notNullValue()));
84 + }
85 +
86 +
87 + /**
88 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
89 + */
90 + @Test
91 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
92 + result = trafficEngineeringMetric.getLinkSubTypeTlvBodyAsByteArray();
93 + assertThat(result, is(notNullValue()));
94 + }
95 +
96 + /**
97 + * Tests to string method.
98 + */
99 + @Test
100 + public void testToString() throws Exception {
101 + assertThat(trafficEngineeringMetric.toString(), is(notNullValue()));
102 + }
103 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for UnknownLinkSubType.
31 + */
32 +public class UnknownLinkSubTypeTest {
33 + private final byte[] packet = {0, 114, 0, 4, 0, 0, 0, 1};
34 + private UnknownLinkSubType unknownLinkSubType;
35 + private TlvHeader header;
36 + private ChannelBuffer channelBuffer;
37 + private byte[] result;
38 +
39 + @Before
40 + public void setUp() throws Exception {
41 + unknownLinkSubType = new UnknownLinkSubType(new TlvHeader());
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + unknownLinkSubType = null;
47 + header = null;
48 + }
49 +
50 + /**
51 + * Tests value() getter method.
52 + */
53 + @Test
54 + public void testValue() throws Exception {
55 + unknownLinkSubType.setValue(packet);
56 + assertThat(unknownLinkSubType.value(), is(notNullValue()));
57 + }
58 +
59 + /**
60 + * Tests value() setter method.
61 + */
62 + @Test
63 + public void testSetValue() throws Exception {
64 + unknownLinkSubType.setValue(packet);
65 + assertThat(unknownLinkSubType.value(), is(notNullValue()));
66 + }
67 +
68 + /**
69 + * Tests readFrom() method.
70 + */
71 + @Test
72 + public void testReadFrom() throws Exception {
73 + header = new TlvHeader();
74 + header.setTlvLength(8);
75 + header.setTlvType(114);
76 + unknownLinkSubType = new UnknownLinkSubType(header);
77 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
78 + unknownLinkSubType.readFrom(channelBuffer);
79 + assertThat(unknownLinkSubType, is(notNullValue()));
80 + }
81 +
82 + /**
83 + * Tests asBytes() method.
84 + */
85 + @Test(expected = Exception.class)
86 + public void testAsBytes() throws Exception {
87 + result = unknownLinkSubType.asBytes();
88 + assertThat(result, is(notNullValue()));
89 + }
90 +
91 +
92 + /**
93 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
94 + */
95 + @Test
96 + public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
97 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
98 + unknownLinkSubType.readFrom(channelBuffer);
99 + result = unknownLinkSubType.getLinkSubTypeTlvBodyAsByteArray();
100 + assertThat(result, is(notNullValue()));
101 + }
102 +
103 + /**
104 + * Tests to string method.
105 + */
106 + @Test
107 + public void testToString() throws Exception {
108 + assertThat(unknownLinkSubType.toString(), is(notNullValue()));
109 + }
110 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.linksubtype;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.is;
27 +import static org.hamcrest.Matchers.notNullValue;
28 +
29 +/**
30 + * Unit test class for OspfRouterId.
31 + */
32 +public class UnreservedBandwidthTest {
33 +
34 + private final byte[] packet = {0, 0, 0, 1};
35 + private UnreservedBandwidth unreservedBandwidth;
36 + private TlvHeader header;
37 + private byte[] result;
38 + private ChannelBuffer channelBuffer;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + unreservedBandwidth = new UnreservedBandwidth(new TlvHeader());
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + unreservedBandwidth = null;
48 + header = null;
49 + result = null;
50 + channelBuffer = null;
51 + }
52 +
53 + /**
54 + * Tests to string method.
55 + */
56 + @Test
57 + public void testToString() throws Exception {
58 + assertThat(unreservedBandwidth.toString(), is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests addUnReservedBandwidth() method.
63 + */
64 + @Test
65 + public void testAddUnReservedBandwidth() throws Exception {
66 + unreservedBandwidth.addUnReservedBandwidth(123456.78f);
67 + assertThat(unreservedBandwidth, is(notNullValue()));
68 + }
69 +
70 +
71 + /**
72 + * Tests readFrom() method.
73 + */
74 + @Test
75 + public void testReadFrom() throws Exception {
76 + header = new TlvHeader();
77 + header.setTlvLength(4);
78 + header.setTlvType(8);
79 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
80 + unreservedBandwidth = new UnreservedBandwidth(header);
81 + unreservedBandwidth.readFrom(channelBuffer);
82 + unreservedBandwidth.readFrom(channelBuffer);
83 + assertThat(unreservedBandwidth, is(notNullValue()));
84 + }
85 +
86 + /**
87 + * Tests asBytes() method.
88 + */
89 + @Test
90 + public void testAsBytes() throws Exception {
91 + result = unreservedBandwidth.asBytes();
92 + assertThat(result, is(notNullValue()));
93 + }
94 +
95 +
96 + /**
97 + * Tests getLinkSubTypeTlvBodyAsByteArray() method.
98 + */
99 + @Test
100 + public void testGetLinkSubTypeTLVBodyAsByteArray() throws Exception {
101 + result = unreservedBandwidth.getLinkSubTypeTlvBodyAsByteArray();
102 + assertThat(result, is(notNullValue()));
103 + }
104 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.*;
27 +
28 +/**
29 + * Unit test class for LinkTlv.
30 + */
31 +public class LinkTlvTest {
32 +
33 + private final byte[] packet1 = {0, 9, 0, 4, 0, 0, 0, 1};
34 + private final byte[] packet2 = {0, 1, 0, 4, 0, 0, 0, 1};
35 + private final byte[] packet3 = {0, 2, 0, 4, 0, 0, 0, 1};
36 + private final byte[] packet4 = {0, 3, 0, 4, 0, 0, 0, 1};
37 + private final byte[] packet5 = {0, 4, 0, 4, 0, 0, 0, 1};
38 + private final byte[] packet6 = {0, 6, 0, 4, 0, 0, 0, 1};
39 + private final byte[] packet7 = {0, 7, 0, 4, 0, 0, 0, 1};
40 + private final byte[] packet8 = {0, 8, 0, 4, 0, 0, 0, 1};
41 + private final byte[] packet9 = {0, 9, 0, 4, 0, 0, 0, 1,
42 + 0, 9, 0, 4, 0, 0, 0, 1,
43 + 0, 1, 0, 4, 0, 0, 0, 1,
44 + 0, 2, 0, 4, 0, 0, 0, 1,
45 + 0, 3, 0, 4, 0, 0, 0, 1,
46 + 0, 4, 0, 4, 0, 0, 0, 1,
47 + 0, 6, 0, 4, 0, 0, 0, 1,
48 + 0, 7, 0, 4, 0, 0, 0, 1,
49 + 0, 8, 0, 4, 0, 0, 0, 1,
50 + };
51 + private LinkTlv linkTlv;
52 + private TlvHeader header;
53 + private ChannelBuffer channelBuffer;
54 + private byte[] result;
55 +
56 + @Before
57 + public void setUp() throws Exception {
58 + linkTlv = new LinkTlv(new TlvHeader());
59 +
60 + }
61 +
62 + @After
63 + public void tearDown() throws Exception {
64 + linkTlv = null;
65 + header = null;
66 + channelBuffer = null;
67 + result = null;
68 + }
69 +
70 + /**
71 + * Tests to string method.
72 + */
73 + @Test
74 + public void testToString() throws Exception {
75 + assertThat(linkTlv.toString(), is(notNullValue()));
76 + }
77 +
78 + /**
79 + * Tests readFrom() method.
80 + */
81 + @Test
82 + public void testReadFrom() throws Exception {
83 +
84 + header = new TlvHeader();
85 + header.setTlvLength(8);
86 + header.setTlvType(9);
87 + linkTlv = new LinkTlv(header);
88 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
89 + linkTlv.readFrom(channelBuffer);
90 + assertThat(linkTlv, is(notNullValue()));
91 +
92 + header = new TlvHeader();
93 + header.setTlvLength(8);
94 + header.setTlvType(1);
95 + linkTlv = new LinkTlv(header);
96 + channelBuffer = ChannelBuffers.copiedBuffer(packet2);
97 + linkTlv.readFrom(channelBuffer);
98 + assertThat(linkTlv, is(notNullValue()));
99 +
100 + header = new TlvHeader();
101 + header.setTlvLength(8);
102 + header.setTlvType(2);
103 + linkTlv = new LinkTlv(header);
104 + channelBuffer = ChannelBuffers.copiedBuffer(packet3);
105 + linkTlv.readFrom(channelBuffer);
106 + assertThat(linkTlv, is(notNullValue()));
107 +
108 + header = new TlvHeader();
109 + header.setTlvLength(8);
110 + header.setTlvType(3);
111 + linkTlv = new LinkTlv(header);
112 + channelBuffer = ChannelBuffers.copiedBuffer(packet4);
113 + linkTlv.readFrom(channelBuffer);
114 + assertThat(linkTlv, is(notNullValue()));
115 +
116 + header = new TlvHeader();
117 + header.setTlvLength(8);
118 + header.setTlvType(4);
119 + linkTlv = new LinkTlv(header);
120 + channelBuffer = ChannelBuffers.copiedBuffer(packet5);
121 + linkTlv.readFrom(channelBuffer);
122 + assertThat(linkTlv, is(notNullValue()));
123 +
124 + header = new TlvHeader();
125 + header.setTlvLength(8);
126 + header.setTlvType(5);
127 + linkTlv = new LinkTlv(header);
128 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
129 + linkTlv.readFrom(channelBuffer);
130 + assertThat(linkTlv, is(notNullValue()));
131 +
132 + header = new TlvHeader();
133 + header.setTlvLength(8);
134 + header.setTlvType(6);
135 + linkTlv = new LinkTlv(header);
136 + channelBuffer = ChannelBuffers.copiedBuffer(packet6);
137 + linkTlv.readFrom(channelBuffer);
138 + assertThat(linkTlv, is(notNullValue()));
139 +
140 + header = new TlvHeader();
141 + header.setTlvLength(8);
142 + header.setTlvType(7);
143 + linkTlv = new LinkTlv(header);
144 + channelBuffer = ChannelBuffers.copiedBuffer(packet7);
145 + linkTlv.readFrom(channelBuffer);
146 + assertThat(linkTlv, is(notNullValue()));
147 +
148 + header = new TlvHeader();
149 + header.setTlvLength(8);
150 + header.setTlvType(8);
151 + linkTlv = new LinkTlv(header);
152 + channelBuffer = ChannelBuffers.copiedBuffer(packet8);
153 + linkTlv.readFrom(channelBuffer);
154 + assertThat(linkTlv, is(notNullValue()));
155 + assertThat(linkTlv, instanceOf(LinkTlv.class));
156 + }
157 +
158 + /**
159 + * Tests asBytes() method.
160 + */
161 + @Test
162 + public void testAsBytes() throws Exception {
163 + result = linkTlv.asBytes();
164 + assertThat(result, is(notNullValue()));
165 + }
166 +
167 +
168 + /**
169 + * Tests getTlvBodyAsByteArray() method.
170 + */
171 + @Test
172 + public void testGetTlvBodyAsByteArray() throws Exception {
173 +
174 + channelBuffer = ChannelBuffers.copiedBuffer(packet9);
175 + linkTlv.readFrom(channelBuffer);
176 +
177 + result = linkTlv.getTlvBodyAsByteArray();
178 + assertThat(result, is(notNullValue()));
179 + }
180 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ospf.protocol.lsa.tlvtypes;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onlab.packet.Ip4Address;
24 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
25 +
26 +import static org.hamcrest.MatcherAssert.assertThat;
27 +import static org.hamcrest.Matchers.*;
28 +
29 +/**
30 + * Unit test class for RouterTlv.
31 + */
32 +public class RouterTlvTest {
33 +
34 + private final byte[] packet = {1, 1, 1, 1};
35 + private final byte[] packet1 = {1, 1, 1};
36 + private RouterTlv rtlv;
37 + private TlvHeader header;
38 + private ChannelBuffer channelBuffer;
39 + private byte[] result;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + rtlv = new RouterTlv(new TlvHeader());
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + rtlv = null;
49 + header = null;
50 + channelBuffer = null;
51 + result = null;
52 + }
53 +
54 + /**
55 + * Tests routerAddress() getter method.
56 + */
57 + @Test
58 + public void testGetRouterAddress() throws Exception {
59 + rtlv.setRouterAddress(Ip4Address.valueOf("1.1.1.1"));
60 + assertThat(rtlv.routerAddress(), is(Ip4Address.valueOf("1.1.1.1")));
61 + }
62 +
63 + /**
64 + * Tests routerAddress() setter method.
65 + */
66 + @Test
67 + public void testSetRouterAddress() throws Exception {
68 + rtlv.setRouterAddress(Ip4Address.valueOf("1.1.1.1"));
69 + assertThat(rtlv.routerAddress(), is(Ip4Address.valueOf("1.1.1.1")));
70 + }
71 +
72 + /**
73 + * Tests readFrom() method.
74 + */
75 + @Test
76 + public void testReadFrom() throws Exception {
77 + header = new TlvHeader();
78 + header.setTlvType(1);
79 + header.setTlvLength(4);
80 + rtlv = new RouterTlv(header);
81 + channelBuffer = ChannelBuffers.copiedBuffer(packet);
82 + rtlv.readFrom(channelBuffer);
83 + assertThat(rtlv, is(notNullValue()));
84 + assertThat(rtlv, instanceOf(RouterTlv.class));
85 + }
86 +
87 + /**
88 + * Tests readFrom() method.
89 + */
90 + @Test(expected = Exception.class)
91 + public void testReadFrom1() throws Exception {
92 + header = new TlvHeader();
93 + header.setTlvType(1);
94 + header.setTlvLength(4);
95 + rtlv = new RouterTlv(header);
96 + channelBuffer = ChannelBuffers.copiedBuffer(packet1);
97 + rtlv.readFrom(channelBuffer);
98 + assertThat(rtlv, is(notNullValue()));
99 + assertThat(rtlv, instanceOf(RouterTlv.class));
100 + }
101 +
102 + /**
103 + * Tests asBytes() method.
104 + */
105 + @Test(expected = Exception.class)
106 + public void testAsBytes() throws Exception {
107 + result = rtlv.asBytes();
108 + assertThat(result, is(notNullValue()));
109 + }
110 +
111 + /**
112 + * Tests getTlvBodyAsByteArray() method.
113 + */
114 + @Test(expected = Exception.class)
115 + public void testGetTLVBodyAsByteArray() throws Exception {
116 + result = rtlv.getTlvBodyAsByteArray();
117 + assertThat(result, is(notNullValue()));
118 + }
119 +
120 + /**
121 + * Tests to string method.
122 + */
123 + @Test
124 + public void testToString() throws Exception {
125 + assertThat(rtlv.toString(), is(notNullValue()));
126 + }
127 +}