blob: 78b4f3fa8fb5e070e4edc1318e04d01e7faa66f4 [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
Jonathan Hart2a655752015-04-07 16:46:33 -070023import static org.onlab.packet.PacketUtils.*;
24
alshabibc4901cd2014-09-05 16:50:40 -070025/**
26 * This class represents an Link Local Control header that is used in Ethernet
27 * 802.3.
28 *
alshabibc4901cd2014-09-05 16:50:40 -070029 *
30 */
31public class LLC extends BasePacket {
Jonathan Hart2a655752015-04-07 16:46:33 -070032
33 public static final byte LLC_HEADER_LENGTH = 3;
34
alshabibc4901cd2014-09-05 16:50:40 -070035 private byte dsap = 0;
36 private byte ssap = 0;
37 private byte ctrl = 0;
38
39 public byte getDsap() {
40 return this.dsap;
41 }
42
43 public void setDsap(final byte dsap) {
44 this.dsap = dsap;
45 }
46
47 public byte getSsap() {
48 return this.ssap;
49 }
50
51 public void setSsap(final byte ssap) {
52 this.ssap = ssap;
53 }
54
55 public byte getCtrl() {
56 return this.ctrl;
57 }
58
59 public void setCtrl(final byte ctrl) {
60 this.ctrl = ctrl;
61 }
62
63 @Override
64 public byte[] serialize() {
65 final byte[] data = new byte[3];
66 final ByteBuffer bb = ByteBuffer.wrap(data);
67 bb.put(this.dsap);
68 bb.put(this.ssap);
69 bb.put(this.ctrl);
70 return data;
71 }
72
73 @Override
74 public IPacket deserialize(final byte[] data, final int offset,
Jonathan Hart2a655752015-04-07 16:46:33 -070075 final int length) {
alshabibc4901cd2014-09-05 16:50:40 -070076 final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
77 this.dsap = bb.get();
78 this.ssap = bb.get();
79 this.ctrl = bb.get();
80 return this;
81 }
Jonathan Hart2a655752015-04-07 16:46:33 -070082
83 /**
84 * Deserializer function for LLC packets.
85 *
86 * @return deserializer function
87 */
88 public static Deserializer<LLC> deserializer() {
89 return (data, offset, length) -> {
90 checkInput(data, offset, length, LLC_HEADER_LENGTH);
91
92 ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
93 LLC llc = new LLC();
94
95 llc.dsap = bb.get();
96 llc.ssap = bb.get();
97 llc.ctrl = bb.get();
98
99 return llc;
100 };
101 }
alshabibc4901cd2014-09-05 16:50:40 -0700102}