blob: 498ce135e86f726a01fd2d34359225b46c9eb869 [file] [log] [blame]
Jian Li10a09062016-07-26 23:58:50 +09001/*
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 */
16package org.onosproject.lisp.msg.protocols;
17
Jian Li26069e22016-08-10 22:00:52 +090018import io.netty.buffer.ByteBuf;
19import org.onosproject.lisp.msg.exceptions.LispParseError;
Jian Li10a09062016-07-26 23:58:50 +090020import org.onosproject.lisp.msg.types.LispAfiAddress;
21
22/**
23 * LISP EID record section which is part of LISP map request message.
24 */
Jian Li631e62a2016-08-03 22:42:00 +090025public final class LispEidRecord {
Jian Li10a09062016-07-26 23:58:50 +090026
27 private final byte maskLength;
28 private final LispAfiAddress prefix;
29
30 /**
31 * Initializes LispEidRecord with mask length and EID prefix.
32 *
33 * @param maskLength mask length
34 * @param prefix EID prefix
35 */
36 public LispEidRecord(byte maskLength, LispAfiAddress prefix) {
37 this.maskLength = maskLength;
38 this.prefix = prefix;
39 }
40
41 /**
42 * Obtains mask length of the EID Record.
43 *
44 * @return mask length of the EID Record
45 */
46 public byte getMaskLength() {
47 return maskLength;
48 }
49
50 /**
51 * Obtains EID prefix.
52 *
53 * @return EID prefix
54 */
55 public LispAfiAddress getPrefix() {
56 return prefix;
57 }
Jian Li26069e22016-08-10 22:00:52 +090058
59 /**
60 * A private LISP message reader for EidRecord portion.
61 */
62 private static class EidRecordReader implements LispMessageReader<LispEidRecord> {
63
Jian Li47671902016-08-11 01:18:18 +090064 private static final int RESERVED_SKIP_LENGTH = 1;
65
Jian Li26069e22016-08-10 22:00:52 +090066 @Override
67 public LispEidRecord readFrom(ByteBuf byteBuf) throws LispParseError {
Jian Li47671902016-08-11 01:18:18 +090068
69 // let's skip the reserved field
70 byteBuf.skipBytes(RESERVED_SKIP_LENGTH);
71
72 short maskLength = (short) byteBuf.readUnsignedShort();
73
74 // TODO: need to de-serialize AFI address
75 LispAfiAddress prefix = null;
76
77 return new LispEidRecord((byte) maskLength, prefix);
Jian Li26069e22016-08-10 22:00:52 +090078 }
79 }
Jian Li10a09062016-07-26 23:58:50 +090080}