blob: 41330493b559c10430e1d3ca207cf5ca108eb92c [file] [log] [blame]
Yi Tsengca34e1d2017-07-18 16:16:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengca34e1d2017-07-18 16:16:25 -07003 *
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
18package org.onlab.packet.dhcp;
19
Yi Tsengb4fdb042017-08-07 13:32:32 -070020import com.google.common.base.MoreObjects;
Yi Tsengca34e1d2017-07-18 16:16:25 -070021import org.onlab.packet.DHCP6;
22import org.onlab.packet.Deserializer;
23import org.onlab.packet.IPacket;
24
25/**
26 * Relay option for DHCPv6.
27 * Based on RFC-3315.
28 */
29public final class Dhcp6RelayOption extends Dhcp6Option {
30 @Override
31 public short getCode() {
32 return DHCP6.OptionCode.RELAY_MSG.value();
33 }
34
35 @Override
36 public short getLength() {
37 return (short) payload.serialize().length;
38 }
39
Yi Tsengb4fdb042017-08-07 13:32:32 -070040 @Override
41 public byte[] getData() {
42 return this.payload.serialize();
43 }
44
Yi Tsengca34e1d2017-07-18 16:16:25 -070045 /**
46 * Default constructor.
47 */
48 public Dhcp6RelayOption() {
49 }
50
51 /**
52 * Constructs a DHCPv6 relay option with DHCPv6 option.
53 *
54 * @param dhcp6Option the DHCPv6 option
55 */
56 public Dhcp6RelayOption(Dhcp6Option dhcp6Option) {
57 super(dhcp6Option);
58 }
59
60 /**
61 * Gets deserializer for DHCPv6 relay option.
62 *
63 * @return the deserializer
64 */
65 public static Deserializer<Dhcp6Option> deserializer() {
66 return (data, offset, len) -> {
67 Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, len);
68 IPacket payload = DHCP6.deserializer()
69 .deserialize(dhcp6Option.getData(), 0, dhcp6Option.getLength());
70 Dhcp6RelayOption relayOption = new Dhcp6RelayOption(dhcp6Option);
71 relayOption.setPayload(payload);
72 payload.setParent(relayOption);
73 return relayOption;
74 };
75 }
Yi Tsengb4fdb042017-08-07 13:32:32 -070076
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(getClass())
80 .add("code", getCode())
81 .add("length", getLength())
82 .add("data", payload.toString())
83 .toString();
84 }
Yi Tsengca34e1d2017-07-18 16:16:25 -070085}