Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [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.lisp.msg.protocols; |
| 17 | |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 18 | import io.netty.buffer.ByteBuf; |
| 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame^] | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 21 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 22 | |
| 23 | /** |
| 24 | * LISP EID record section which is part of LISP map request message. |
| 25 | */ |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 26 | public final class LispEidRecord { |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 27 | |
| 28 | private final byte maskLength; |
| 29 | private final LispAfiAddress prefix; |
| 30 | |
| 31 | /** |
| 32 | * Initializes LispEidRecord with mask length and EID prefix. |
| 33 | * |
| 34 | * @param maskLength mask length |
| 35 | * @param prefix EID prefix |
| 36 | */ |
| 37 | public LispEidRecord(byte maskLength, LispAfiAddress prefix) { |
| 38 | this.maskLength = maskLength; |
| 39 | this.prefix = prefix; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Obtains mask length of the EID Record. |
| 44 | * |
| 45 | * @return mask length of the EID Record |
| 46 | */ |
| 47 | public byte getMaskLength() { |
| 48 | return maskLength; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Obtains EID prefix. |
| 53 | * |
| 54 | * @return EID prefix |
| 55 | */ |
| 56 | public LispAfiAddress getPrefix() { |
| 57 | return prefix; |
| 58 | } |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * A private LISP message reader for EidRecord portion. |
| 62 | */ |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame^] | 63 | public static class EidRecordReader implements LispMessageReader<LispEidRecord> { |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 64 | |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 65 | private static final int RESERVED_SKIP_LENGTH = 1; |
| 66 | |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 67 | @Override |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame^] | 68 | public LispEidRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 69 | |
| 70 | // let's skip the reserved field |
| 71 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); |
| 72 | |
| 73 | short maskLength = (short) byteBuf.readUnsignedShort(); |
| 74 | |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame^] | 75 | LispAfiAddress prefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 76 | |
| 77 | return new LispEidRecord((byte) maskLength, prefix); |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 78 | } |
| 79 | } |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 80 | } |