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 |
|
| 17 | package org.onosproject.pcepio.types;
|
| 18 |
|
| 19 | import java.util.Objects;
|
| 20 |
|
| 21 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 22 | import org.onosproject.pcepio.protocol.PcepVersion;
|
| 23 | import org.slf4j.Logger;
|
| 24 | import org.slf4j.LoggerFactory;
|
| 25 |
|
| 26 | import com.google.common.base.MoreObjects;
|
| 27 |
|
| 28 | /**
|
| 29 | * Path Key SubObject: When a PCC needs to expand a path-key in order to expand a CPS, it
|
| 30 | * issues a Path Computation Request (PCReq) to the PCE identified in
|
| 31 | * the PKS in the RSVP-TE ERO that it is processing. The PCC supplies
|
| 32 | * the PKS to be expanded in a PATH-KEY SubObject in the PCReq message.
|
| 33 | */
|
| 34 | public class PathKeySubObject implements PcepValueType {
|
| 35 |
|
| 36 | /*
|
| 37 | Pathkey subobject(RFC 5520):
|
| 38 | 0 1 2 3
|
| 39 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 40 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 41 | |L| Type | Length | Path-Key |
|
| 42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 43 | | PCE ID (4 bytes) |
|
| 44 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 45 | */
|
| 46 |
|
| 47 | protected static final Logger log = LoggerFactory.getLogger(PathKeySubObject.class);
|
| 48 |
|
| 49 | public static final byte TYPE = 0x40;
|
| 50 | public static final byte LENGTH = 8;
|
| 51 | private final short pathKey;
|
| 52 | private final int pceID;
|
| 53 |
|
| 54 | /**
|
| 55 | * Constructor for Path Key sub Object which initializes pathKey and pceId.
|
| 56 | *
|
| 57 | * @param pathKey path key provided by PCC
|
| 58 | * @param pceID ID for the PCE
|
| 59 | */
|
| 60 | public PathKeySubObject(short pathKey, int pceID) {
|
| 61 | this.pathKey = pathKey;
|
| 62 | this.pceID = pceID;
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Creates Path Key sub Object which initializes pathKey and pceId.
|
| 67 | *
|
| 68 | * @param pathKey path key provided by PCC
|
| 69 | * @param pceID PCE id
|
| 70 | * @return new object of type path key sub object
|
| 71 | */
|
| 72 | public static PathKeySubObject of(short pathKey, int pceID) {
|
| 73 | return new PathKeySubObject(pathKey, pceID);
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * Returns Path Key.
|
| 78 | *
|
| 79 | * @return pathKey
|
| 80 | */
|
| 81 | public short getPathKey() {
|
| 82 | return pathKey;
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | * Returns pceID.
|
| 87 | *
|
| 88 | * @return pceID
|
| 89 | */
|
| 90 | public int getPceId() {
|
| 91 | return pceID;
|
| 92 | }
|
| 93 |
|
| 94 | @Override
|
| 95 | public PcepVersion getVersion() {
|
| 96 | return PcepVersion.PCEP_1;
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | public short getType() {
|
| 101 | return TYPE;
|
| 102 | }
|
| 103 |
|
| 104 | @Override
|
| 105 | public short getLength() {
|
| 106 | return LENGTH;
|
| 107 | }
|
| 108 |
|
| 109 | @Override
|
| 110 | public int hashCode() {
|
| 111 | return Objects.hash(pathKey, pceID);
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | public boolean equals(Object obj) {
|
| 116 | if (this == obj) {
|
| 117 | return true;
|
| 118 | }
|
| 119 | if (obj instanceof PathKeySubObject) {
|
| 120 | PathKeySubObject other = (PathKeySubObject) obj;
|
| 121 | return Objects.equals(this.pathKey, other.pathKey) && Objects.equals(this.pceID, other.pceID);
|
| 122 | }
|
| 123 | return false;
|
| 124 | }
|
| 125 |
|
| 126 | @Override
|
| 127 | public int write(ChannelBuffer c) {
|
| 128 | int iLenStartIndex = c.writerIndex();
|
| 129 | c.writeShort(TYPE);
|
| 130 | c.writeShort(LENGTH);
|
| 131 |
|
| 132 | c.writeShort(pathKey);
|
| 133 | c.writeInt(pceID);
|
| 134 |
|
| 135 | return c.writerIndex() - iLenStartIndex;
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * Reads the channel buffer and returns new path key sub objects.
|
| 140 | *
|
| 141 | * @param c of type channel buffer
|
| 142 | * @return object of type path key sub object
|
| 143 | */
|
| 144 | public static PcepValueType read(ChannelBuffer c) {
|
| 145 | Short pathKey = c.readShort();
|
| 146 | int pceID = c.readInt();
|
| 147 | return new PathKeySubObject(pathKey, pceID);
|
| 148 | }
|
| 149 |
|
| 150 | @Override
|
bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 151 | public String toString() {
|
| 152 | return MoreObjects.toStringHelper(getClass())
|
bharat saraswal | e180630 | 2015-08-21 12:16:46 +0530 | [diff] [blame] | 153 | .add("Type", TYPE)
|
| 154 | .add("Length", LENGTH)
|
| 155 | .add("PathKey", pathKey)
|
| 156 | .add("PceID", pceID)
|
bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 157 | .toString();
|
| 158 | }
|
| 159 | }
|