Committed by
Gerrit Code Review
[Emu][onos-2603] - Implement LinkState attributes
Change-Id: I1a29f3d5e5578314816357bd6dc909806bcd1c4a
Showing
3 changed files
with
392 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 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.bgpio.types.attr; | ||
| 17 | + | ||
| 18 | +import java.util.Arrays; | ||
| 19 | + | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
| 22 | +import org.onosproject.bgpio.types.BGPErrorType; | ||
| 23 | +import org.onosproject.bgpio.types.BGPValueType; | ||
| 24 | +import org.onosproject.bgpio.util.Validation; | ||
| 25 | +import org.slf4j.Logger; | ||
| 26 | +import org.slf4j.LoggerFactory; | ||
| 27 | + | ||
| 28 | +import com.google.common.base.MoreObjects; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Implements BGP attribute ISIS Area Identifier. | ||
| 32 | + */ | ||
| 33 | +public class BgpAttrNodeIsIsAreaId implements BGPValueType { | ||
| 34 | + | ||
| 35 | + protected static final Logger log = LoggerFactory | ||
| 36 | + .getLogger(BgpAttrNodeIsIsAreaId.class); | ||
| 37 | + | ||
| 38 | + public static final int ATTRNODE_ISISAREAID = 1027; | ||
| 39 | + | ||
| 40 | + /* IS-IS Area Identifier TLV */ | ||
| 41 | + private byte[] isisAreaId; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Constructor to initialize value. | ||
| 45 | + * | ||
| 46 | + * @param isisAreaId ISIS area Identifier | ||
| 47 | + */ | ||
| 48 | + public BgpAttrNodeIsIsAreaId(byte[] isisAreaId) { | ||
| 49 | + this.isisAreaId = Arrays.copyOf(isisAreaId, isisAreaId.length); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns object of this class with specified values. | ||
| 54 | + * | ||
| 55 | + * @param isisAreaId ISIS area Identifier | ||
| 56 | + * @return object of BgpAttrNodeIsIsAreaId | ||
| 57 | + */ | ||
| 58 | + public static BgpAttrNodeIsIsAreaId of(final byte[] isisAreaId) { | ||
| 59 | + return new BgpAttrNodeIsIsAreaId(isisAreaId); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Reads the IS-IS Area Identifier. | ||
| 64 | + * | ||
| 65 | + * @param cb ChannelBuffer | ||
| 66 | + * @return object of BgpAttrNodeIsIsAreaId | ||
| 67 | + * @throws BGPParseException while parsing BgpAttrNodeIsIsAreaId | ||
| 68 | + */ | ||
| 69 | + public static BgpAttrNodeIsIsAreaId read(ChannelBuffer cb) | ||
| 70 | + throws BGPParseException { | ||
| 71 | + byte[] isisAreaId; | ||
| 72 | + | ||
| 73 | + short lsAttrLength = cb.readShort(); | ||
| 74 | + | ||
| 75 | + if (cb.readableBytes() < lsAttrLength) { | ||
| 76 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
| 77 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
| 78 | + lsAttrLength); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + isisAreaId = new byte[lsAttrLength]; | ||
| 82 | + cb.readBytes(isisAreaId); | ||
| 83 | + | ||
| 84 | + return BgpAttrNodeIsIsAreaId.of(isisAreaId); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Returns ISIS area Identifier. | ||
| 89 | + * | ||
| 90 | + * @return Area ID | ||
| 91 | + */ | ||
| 92 | + public byte[] attrNodeIsIsAreaId() { | ||
| 93 | + return isisAreaId; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public short getType() { | ||
| 98 | + return ATTRNODE_ISISAREAID; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public int hashCode() { | ||
| 103 | + return Arrays.hashCode(isisAreaId); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public boolean equals(Object obj) { | ||
| 108 | + if (this == obj) { | ||
| 109 | + return true; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + if (obj instanceof BgpAttrNodeIsIsAreaId) { | ||
| 113 | + BgpAttrNodeIsIsAreaId other = (BgpAttrNodeIsIsAreaId) obj; | ||
| 114 | + return Arrays.equals(isisAreaId, other.isisAreaId); | ||
| 115 | + } | ||
| 116 | + return false; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public int write(ChannelBuffer cb) { | ||
| 121 | + // TODO This will be implemented in the next version | ||
| 122 | + return 0; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public String toString() { | ||
| 127 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
| 128 | + .add("isisAreaId", isisAreaId).toString(); | ||
| 129 | + } | ||
| 130 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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.bgpio.types.attr; | ||
| 17 | + | ||
| 18 | +import java.util.Arrays; | ||
| 19 | + | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
| 22 | +import org.onosproject.bgpio.types.BGPErrorType; | ||
| 23 | +import org.onosproject.bgpio.types.BGPValueType; | ||
| 24 | +import org.onosproject.bgpio.util.Validation; | ||
| 25 | +import org.slf4j.Logger; | ||
| 26 | +import org.slf4j.LoggerFactory; | ||
| 27 | + | ||
| 28 | +import com.google.common.base.MoreObjects; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Implements BGP attribute node name. | ||
| 32 | + */ | ||
| 33 | +public class BgpAttrNodeName implements BGPValueType { | ||
| 34 | + | ||
| 35 | + protected static final Logger log = LoggerFactory | ||
| 36 | + .getLogger(BgpAttrNodeName.class); | ||
| 37 | + | ||
| 38 | + public static final int ATTRNODE_NAME = 1026; | ||
| 39 | + | ||
| 40 | + /* Node Name */ | ||
| 41 | + private byte[] nodeName; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Constructor to initialize value. | ||
| 45 | + * | ||
| 46 | + * @param nodeName node name | ||
| 47 | + */ | ||
| 48 | + public BgpAttrNodeName(byte[] nodeName) { | ||
| 49 | + this.nodeName = Arrays.copyOf(nodeName, nodeName.length); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns object of this class with specified values. | ||
| 54 | + * | ||
| 55 | + * @param nodeName node name | ||
| 56 | + * @return object of BgpAttrNodeName | ||
| 57 | + */ | ||
| 58 | + public static BgpAttrNodeName of(final byte[] nodeName) { | ||
| 59 | + return new BgpAttrNodeName(nodeName); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Reads the LS attribute node name. | ||
| 64 | + * | ||
| 65 | + * @param cb ChannelBuffer | ||
| 66 | + * @return object of BgpAttrNodeName | ||
| 67 | + * @throws BGPParseException while parsing BgpAttrNodeName | ||
| 68 | + */ | ||
| 69 | + public static BgpAttrNodeName read(ChannelBuffer cb) | ||
| 70 | + throws BGPParseException { | ||
| 71 | + byte[] nodeName; | ||
| 72 | + | ||
| 73 | + short lsAttrLength = cb.readShort(); | ||
| 74 | + | ||
| 75 | + if (cb.readableBytes() < lsAttrLength) { | ||
| 76 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
| 77 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
| 78 | + lsAttrLength); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + nodeName = new byte[lsAttrLength]; | ||
| 82 | + cb.readBytes(nodeName); | ||
| 83 | + return BgpAttrNodeName.of(nodeName); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Returns LS attribute node name. | ||
| 88 | + * | ||
| 89 | + * @return node name | ||
| 90 | + */ | ||
| 91 | + public byte[] attrNodeName() { | ||
| 92 | + return nodeName; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public short getType() { | ||
| 97 | + return ATTRNODE_NAME; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Override | ||
| 101 | + public int hashCode() { | ||
| 102 | + return Arrays.hashCode(nodeName); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public boolean equals(Object obj) { | ||
| 107 | + if (this == obj) { | ||
| 108 | + return true; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + if (obj instanceof BgpAttrNodeName) { | ||
| 112 | + BgpAttrNodeName other = (BgpAttrNodeName) obj; | ||
| 113 | + return Arrays.equals(nodeName, other.nodeName); | ||
| 114 | + } | ||
| 115 | + return false; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public int write(ChannelBuffer cb) { | ||
| 120 | + // TODO This will be implemented in the next version | ||
| 121 | + return 0; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public String toString() { | ||
| 126 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
| 127 | + .add("nodeName", nodeName).toString(); | ||
| 128 | + } | ||
| 129 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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.bgpio.types.attr; | ||
| 17 | + | ||
| 18 | +import java.util.Arrays; | ||
| 19 | + | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
| 22 | +import org.onosproject.bgpio.types.BGPErrorType; | ||
| 23 | +import org.onosproject.bgpio.types.BGPValueType; | ||
| 24 | +import org.onosproject.bgpio.util.Validation; | ||
| 25 | +import org.slf4j.Logger; | ||
| 26 | +import org.slf4j.LoggerFactory; | ||
| 27 | + | ||
| 28 | +import com.google.common.base.MoreObjects; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Implements BGP attribute opaque node. | ||
| 32 | + */ | ||
| 33 | +public class BgpAttrOpaqueNode implements BGPValueType { | ||
| 34 | + | ||
| 35 | + protected static final Logger log = LoggerFactory | ||
| 36 | + .getLogger(BgpAttrOpaqueNode.class); | ||
| 37 | + | ||
| 38 | + public static final int ATTRNODE_OPAQUEDATA = 1025; | ||
| 39 | + | ||
| 40 | + /* Opaque Node Attribute */ | ||
| 41 | + private byte[] opaqueNodeAttribute; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Constructor to initialize parameter. | ||
| 45 | + * | ||
| 46 | + * @param opaqueNodeAttribute opaque node attribute | ||
| 47 | + */ | ||
| 48 | + public BgpAttrOpaqueNode(byte[] opaqueNodeAttribute) { | ||
| 49 | + this.opaqueNodeAttribute = Arrays.copyOf(opaqueNodeAttribute, opaqueNodeAttribute.length); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns object of this class with specified values. | ||
| 54 | + * | ||
| 55 | + * @param opaqueNodeAttribute Prefix Metric | ||
| 56 | + * @return object of BgpAttrOpaqueNode | ||
| 57 | + */ | ||
| 58 | + public static BgpAttrOpaqueNode of(byte[] opaqueNodeAttribute) { | ||
| 59 | + return new BgpAttrOpaqueNode(opaqueNodeAttribute); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Reads the Opaque Node Properties. | ||
| 64 | + * | ||
| 65 | + * @param cb ChannelBuffer | ||
| 66 | + * @return object of BgpAttrOpaqueNode | ||
| 67 | + * @throws BGPParseException while parsing BgpAttrOpaqueNode | ||
| 68 | + */ | ||
| 69 | + public static BgpAttrOpaqueNode read(ChannelBuffer cb) | ||
| 70 | + throws BGPParseException { | ||
| 71 | + | ||
| 72 | + byte[] opaqueNodeAttribute; | ||
| 73 | + | ||
| 74 | + short lsAttrLength = cb.readShort(); | ||
| 75 | + | ||
| 76 | + if (cb.readableBytes() < lsAttrLength) { | ||
| 77 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
| 78 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
| 79 | + lsAttrLength); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + opaqueNodeAttribute = new byte[lsAttrLength]; | ||
| 83 | + cb.readBytes(opaqueNodeAttribute); | ||
| 84 | + | ||
| 85 | + return BgpAttrOpaqueNode.of(opaqueNodeAttribute); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * Returns opaque node attribute. | ||
| 90 | + * | ||
| 91 | + * @return LS node attribute value | ||
| 92 | + */ | ||
| 93 | + public byte[] attrOpaqueNode() { | ||
| 94 | + return opaqueNodeAttribute; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public short getType() { | ||
| 99 | + return ATTRNODE_OPAQUEDATA; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public int hashCode() { | ||
| 104 | + return Arrays.hashCode(opaqueNodeAttribute); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public boolean equals(Object obj) { | ||
| 109 | + if (this == obj) { | ||
| 110 | + return true; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + if (obj instanceof BgpAttrOpaqueNode) { | ||
| 114 | + BgpAttrOpaqueNode other = (BgpAttrOpaqueNode) obj; | ||
| 115 | + return Arrays | ||
| 116 | + .equals(opaqueNodeAttribute, other.opaqueNodeAttribute); | ||
| 117 | + } | ||
| 118 | + return false; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + @Override | ||
| 122 | + public int write(ChannelBuffer cb) { | ||
| 123 | + // TODO This will be implemented in the next version | ||
| 124 | + return 0; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public String toString() { | ||
| 129 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
| 130 | + .add("opaqueNodeAttribute", opaqueNodeAttribute).toString(); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | +} |
-
Please register or login to post a comment