blob: cb54119a11bd118b1fb7647c953f4cbde81c25f4 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
alshabibc4901cd2014-09-05 16:50:40 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
alshabibc4901cd2014-09-05 16:50:40 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
16
17
alshabibc4901cd2014-09-05 16:50:40 -070018
19package org.onlab.packet;
20
21import java.nio.ByteBuffer;
22
Jian Li5fc14292015-12-04 11:30:46 -080023import static com.google.common.base.MoreObjects.toStringHelper;
Jonathan Hart2a655752015-04-07 16:46:33 -070024import static org.onlab.packet.PacketUtils.*;
25
alshabibc4901cd2014-09-05 16:50:40 -070026/**
27 * This class represents an Link Local Control header that is used in Ethernet
28 * 802.3.
alshabibc4901cd2014-09-05 16:50:40 -070029 */
30public class LLC extends BasePacket {
Jonathan Hart2a655752015-04-07 16:46:33 -070031
32 public static final byte LLC_HEADER_LENGTH = 3;
33
alshabibc4901cd2014-09-05 16:50:40 -070034 private byte dsap = 0;
35 private byte ssap = 0;
36 private byte ctrl = 0;
37
38 public byte getDsap() {
39 return this.dsap;
40 }
41
42 public void setDsap(final byte dsap) {
43 this.dsap = dsap;
44 }
45
46 public byte getSsap() {
47 return this.ssap;
48 }
49
50 public void setSsap(final byte ssap) {
51 this.ssap = ssap;
52 }
53
54 public byte getCtrl() {
55 return this.ctrl;
56 }
57
58 public void setCtrl(final byte ctrl) {
59 this.ctrl = ctrl;
60 }
61
62 @Override
63 public byte[] serialize() {
64 final byte[] data = new byte[3];
65 final ByteBuffer bb = ByteBuffer.wrap(data);
66 bb.put(this.dsap);
67 bb.put(this.ssap);
68 bb.put(this.ctrl);
69 return data;
70 }
71
Jonathan Hart2a655752015-04-07 16:46:33 -070072
73 /**
74 * Deserializer function for LLC packets.
75 *
76 * @return deserializer function
77 */
78 public static Deserializer<LLC> deserializer() {
79 return (data, offset, length) -> {
80 checkInput(data, offset, length, LLC_HEADER_LENGTH);
81
82 ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
83 LLC llc = new LLC();
84
85 llc.dsap = bb.get();
86 llc.ssap = bb.get();
87 llc.ctrl = bb.get();
88
89 return llc;
90 };
91 }
Jian Li5fc14292015-12-04 11:30:46 -080092
93 @Override
94 public String toString() {
95 return toStringHelper(getClass())
96 .add("dsap", Byte.toString(dsap))
97 .add("ssap", Byte.toString(ssap))
98 .add("ctrl", Byte.toString(ctrl))
99 .toString();
100 }
alshabibc4901cd2014-09-05 16:50:40 -0700101}