bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 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.pcepio.types;
|
| 17 |
|
| 18 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 19 | import org.onosproject.pcepio.protocol.PcepVersion;
|
| 20 |
|
| 21 | import com.google.common.base.MoreObjects;
|
| 22 |
|
| 23 | public class PcepRsvpIpv4ErrorSpec implements PcepRsvpErrorSpec {
|
| 24 |
|
| 25 | /*
|
| 26 | RSVP error spec object header.
|
| 27 | 0 1 2 3
|
| 28 | +-------------+-------------+-------------+-------------+
|
| 29 | | Length (bytes) | Class-Num | C-Type |
|
| 30 | +-------------+-------------+-------------+-------------+
|
| 31 | | |
|
| 32 | // (Object contents) //
|
| 33 | | |
|
| 34 | +-------------+-------------+-------------+-------------+
|
| 35 |
|
| 36 | Ref : ERROR_SPEC @ RFC2205
|
| 37 |
|
| 38 | IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
|
| 39 | +-------------+-------------+-------------+-------------+
|
| 40 | | IPv4 Error Node Address (4 bytes) |
|
| 41 | +-------------+-------------+-------------+-------------+
|
| 42 | | Flags | Error Code | Error Value |
|
| 43 | +-------------+-------------+-------------+-------------+
|
| 44 |
|
| 45 | */
|
| 46 |
|
| 47 | PcepRsvpSpecObjHeader objHeader;
|
| 48 | public static final byte CLASS_NUM = 0x06;
|
| 49 | public static final byte CLASS_TYPE = 0x01;
|
| 50 | public static final byte CLASS_LENGTH = 0x0c;
|
| 51 | private int ipv4Addr;
|
| 52 | private byte flags;
|
| 53 | private byte errCode;
|
| 54 | private short errValue;
|
| 55 |
|
| 56 | /**
|
| 57 | * Constructor to initialize obj header, ipv4 addr, flags, err code and err value.
|
| 58 | *
|
| 59 | * @param objHeader rsvp ipv4 error spec object header
|
| 60 | * @param ipv4Addr ipv4 address
|
| 61 | * @param flags flags value
|
| 62 | * @param errCode error code value
|
| 63 | * @param errValue error value
|
| 64 | */
|
| 65 | public PcepRsvpIpv4ErrorSpec(PcepRsvpSpecObjHeader objHeader, int ipv4Addr, byte flags, byte errCode,
|
| 66 | short errValue) {
|
| 67 | this.objHeader = objHeader;
|
| 68 | this.ipv4Addr = ipv4Addr;
|
| 69 | this.flags = flags;
|
| 70 | this.errCode = errCode;
|
| 71 | this.errValue = errValue;
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Constructor to initialize ipv4 address, flags, err code and err value.
|
| 76 | *
|
| 77 | * @param ipv4Addr ipv4 address
|
| 78 | * @param flags flags value
|
| 79 | * @param errCode error code
|
| 80 | * @param errValue error value
|
| 81 | */
|
| 82 | public PcepRsvpIpv4ErrorSpec(int ipv4Addr, byte flags, byte errCode, short errValue) {
|
| 83 | this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
|
| 84 | this.ipv4Addr = ipv4Addr;
|
| 85 | this.flags = flags;
|
| 86 | this.errCode = errCode;
|
| 87 | this.errValue = errValue;
|
| 88 | }
|
| 89 |
|
| 90 | @Override
|
| 91 | public int write(ChannelBuffer cb) {
|
| 92 | int objLenIndex = objHeader.write(cb);
|
| 93 | cb.writeInt(ipv4Addr);
|
| 94 | cb.writeByte(flags);
|
| 95 | cb.writeByte(errCode);
|
| 96 | cb.writeShort(errValue);
|
| 97 | short objLen = (short) (cb.writerIndex() - objLenIndex);
|
| 98 | cb.setShort(objLenIndex, objLen);
|
| 99 | return objLen;
|
| 100 | }
|
| 101 |
|
| 102 | /**
|
| 103 | * Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object.
|
| 104 | *
|
| 105 | * @param cb channel buffer
|
| 106 | * @return PCEP rsvp IPv4 error spec object
|
| 107 | */
|
| 108 | public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
|
| 109 | PcepRsvpSpecObjHeader objHeader;
|
| 110 | int ipv4Addr;
|
| 111 | byte flags;
|
| 112 | byte errCode;
|
| 113 | short errValue;
|
| 114 |
|
| 115 | objHeader = PcepRsvpSpecObjHeader.read(cb);
|
| 116 | ipv4Addr = cb.readInt();
|
| 117 | flags = cb.readByte();
|
| 118 | errCode = cb.readByte();
|
| 119 | errValue = cb.readShort();
|
| 120 | return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue);
|
| 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | public PcepVersion getVersion() {
|
| 125 | return PcepVersion.PCEP_1;
|
| 126 | }
|
| 127 |
|
| 128 | @Override
|
| 129 | public short getType() {
|
| 130 | return StatefulRsvpErrorSpecTlv.TYPE;
|
| 131 | }
|
| 132 |
|
| 133 | @Override
|
| 134 | public short getLength() {
|
| 135 | return CLASS_LENGTH;
|
| 136 | }
|
| 137 |
|
| 138 | @Override
|
| 139 | public byte getClassNum() {
|
| 140 | return CLASS_NUM;
|
| 141 | }
|
| 142 |
|
| 143 | @Override
|
| 144 | public byte getClassType() {
|
| 145 | return CLASS_TYPE;
|
| 146 | }
|
| 147 |
|
| 148 | @Override
|
| 149 | public void print() {
|
| 150 | // TODO Auto-generated method stub
|
| 151 | }
|
| 152 |
|
| 153 | @Override
|
| 154 | public String toString() {
|
| 155 | return MoreObjects.toStringHelper(getClass())
|
| 156 | .add("IPv4 Address:", ipv4Addr)
|
| 157 | .add("flags:", flags)
|
| 158 | .add("error Code:", errCode)
|
| 159 | .add("error Value:", errValue)
|
| 160 | .toString();
|
| 161 | }
|
| 162 | }
|