blob: bd2739faf599f53bf7e1950af44542c3d3702a5f [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
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
72 @Override
73 public IPacket deserialize(final byte[] data, final int offset,
Jonathan Hart2a655752015-04-07 16:46:33 -070074 final int length) {
alshabibc4901cd2014-09-05 16:50:40 -070075 final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
76 this.dsap = bb.get();
77 this.ssap = bb.get();
78 this.ctrl = bb.get();
79 return this;
80 }
Jonathan Hart2a655752015-04-07 16:46:33 -070081
82 /**
83 * Deserializer function for LLC packets.
84 *
85 * @return deserializer function
86 */
87 public static Deserializer<LLC> deserializer() {
88 return (data, offset, length) -> {
89 checkInput(data, offset, length, LLC_HEADER_LENGTH);
90
91 ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
92 LLC llc = new LLC();
93
94 llc.dsap = bb.get();
95 llc.ssap = bb.get();
96 llc.ctrl = bb.get();
97
98 return llc;
99 };
100 }
Jian Li5fc14292015-12-04 11:30:46 -0800101
102 @Override
103 public String toString() {
104 return toStringHelper(getClass())
105 .add("dsap", Byte.toString(dsap))
106 .add("ssap", Byte.toString(ssap))
107 .add("ctrl", Byte.toString(ctrl))
108 .toString();
109 }
alshabibc4901cd2014-09-05 16:50:40 -0700110}