Dhruv Dhody | e64b93e | 2016-04-20 19:26:55 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.isis.io.isispacket; |
| 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.onlab.packet.MacAddress; |
| 20 | import org.onosproject.isis.controller.IsisMessage; |
| 21 | import org.onosproject.isis.controller.IsisPduType; |
| 22 | |
| 23 | /** |
| 24 | * Representation of ISIS message header. |
| 25 | */ |
| 26 | public class IsisHeader implements IsisMessage { |
| 27 | |
| 28 | private MacAddress sourceMac; |
| 29 | private int interfaceIndex; |
| 30 | private MacAddress interfaceMac; |
| 31 | private int isisPduType; |
| 32 | private byte irpDiscriminator; |
| 33 | private byte pduHeaderLength; |
| 34 | private byte version2; |
| 35 | private byte idLength; |
| 36 | private byte version; |
| 37 | private byte reserved; |
| 38 | private byte maximumAreaAddresses; |
| 39 | |
| 40 | /** |
| 41 | * Returns the interface index on which the message received. |
| 42 | * |
| 43 | * @return interface index on which the message received |
| 44 | */ |
| 45 | public int interfaceIndex() { |
| 46 | return interfaceIndex; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Sets the interface index on which the message received. |
| 51 | * |
| 52 | * @param interfaceIndex interface index on which the message received |
| 53 | */ |
| 54 | public void setInterfaceIndex(int interfaceIndex) { |
| 55 | this.interfaceIndex = interfaceIndex; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the interface mac address on which the message received. |
| 60 | * |
| 61 | * @return interface mac address on which the message received |
| 62 | */ |
| 63 | public MacAddress interfaceMac() { |
| 64 | return interfaceMac; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the mac address of the message sender. |
| 69 | * |
| 70 | * @return mac address of the message sender |
| 71 | */ |
| 72 | public MacAddress sourceMac() { |
| 73 | return sourceMac; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sets the mac address of the message sender. |
| 78 | * |
| 79 | * @param sourceMac mac address of the message sender |
| 80 | */ |
| 81 | public void setSourceMac(MacAddress sourceMac) { |
| 82 | this.sourceMac = sourceMac; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Sets the interface mac address on which the message received. |
| 87 | * |
| 88 | * @param interfaceMac mac address on which the message received |
| 89 | */ |
| 90 | public void setInterfaceMac(MacAddress interfaceMac) { |
| 91 | this.interfaceMac = interfaceMac; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns the version of TLV header. |
| 96 | * |
| 97 | * @return version version of TLV header |
| 98 | */ |
| 99 | public byte version2() { |
| 100 | return version2; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Sets the version of TLV header. |
| 105 | * |
| 106 | * @param version2 version of TLV header |
| 107 | */ |
| 108 | public void setVersion2(byte version2) { |
| 109 | this.version2 = version2; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns maximum area address. |
| 114 | * |
| 115 | * @return maximum area address |
| 116 | */ |
| 117 | public byte maximumAreaAddresses() { |
| 118 | return maximumAreaAddresses; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Sets maximum area address. |
| 123 | * |
| 124 | * @param maximumAreaAddresses maximum area address |
| 125 | */ |
| 126 | public void setMaximumAreaAddresses(byte maximumAreaAddresses) { |
| 127 | this.maximumAreaAddresses = maximumAreaAddresses; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns reserved field value on which data received. |
| 132 | * |
| 133 | * @return reserved |
| 134 | */ |
| 135 | public byte reserved() { |
| 136 | return reserved; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets reserved. |
| 141 | * |
| 142 | * @param reserved reserved |
| 143 | */ |
| 144 | public void setReserved(byte reserved) { |
| 145 | this.reserved = reserved; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Returns version. |
| 150 | * |
| 151 | * @return version |
| 152 | */ |
| 153 | public byte version() { |
| 154 | return version; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Returns ID length. |
| 159 | * |
| 160 | * @return ID length |
| 161 | */ |
| 162 | public byte idLength() { |
| 163 | return idLength; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Sets ID length. |
| 168 | * |
| 169 | * @param idLength ID length |
| 170 | */ |
| 171 | public void setIdLength(byte idLength) { |
| 172 | this.idLength = idLength; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Returns the PDU type. |
| 177 | * |
| 178 | * @return PDU type |
| 179 | */ |
| 180 | public int pduType() { |
| 181 | |
| 182 | return this.isisPduType; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Sets PDU type. |
| 187 | * |
| 188 | * @param isisPduType PDU type |
| 189 | */ |
| 190 | public void setIsisPduType(int isisPduType) { |
| 191 | this.isisPduType = isisPduType; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Sets protocol ID. |
| 196 | * |
| 197 | * @param version protocol ID |
| 198 | */ |
| 199 | public void setVersion(byte version) { |
| 200 | this.version = version; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Returns length indicator. |
| 205 | * |
| 206 | * @return length indicator |
| 207 | */ |
| 208 | public byte pduHeaderLength() { |
| 209 | return pduHeaderLength; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Sets length indicator. |
| 214 | * |
| 215 | * @param pduHeaderLength length indicator |
| 216 | */ |
| 217 | public void setPduHeaderLength(byte pduHeaderLength) { |
| 218 | this.pduHeaderLength = pduHeaderLength; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Returns IRP discriminator. |
| 223 | * |
| 224 | * @return IRP discriminator |
| 225 | */ |
| 226 | public byte irpDiscriminator() { |
| 227 | return irpDiscriminator; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Sets IRP discriminator. |
| 232 | * |
| 233 | * @param irpDiscriminator IRP discriminator |
| 234 | */ |
| 235 | public void setIrpDiscriminator(byte irpDiscriminator) { |
| 236 | |
| 237 | this.irpDiscriminator = irpDiscriminator; |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public IsisPduType isisPduType() { |
| 242 | |
| 243 | return IsisPduType.get(this.isisPduType); |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public void readFrom(ChannelBuffer channelBuffer) { |
| 248 | //implemented in the sub classes |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public byte[] asBytes() { |
| 253 | return null; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Populates ISIS header. |
| 258 | * |
| 259 | * @param isisHeader ISIS header |
| 260 | */ |
| 261 | public void populateHeader(IsisHeader isisHeader) { |
| 262 | this.setIrpDiscriminator(isisHeader.irpDiscriminator()); |
| 263 | this.setPduHeaderLength(isisHeader.pduHeaderLength()); |
| 264 | this.setVersion(isisHeader.version()); |
| 265 | this.setIdLength(isisHeader.idLength()); |
| 266 | this.setIsisPduType(isisHeader.pduType()); |
| 267 | this.setVersion2(isisHeader.version2()); |
| 268 | this.setReserved(isisHeader.reserved()); |
| 269 | this.setMaximumAreaAddresses(isisHeader.maximumAreaAddresses()); |
| 270 | } |
| 271 | } |