Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 18 | |
| 19 | package org.onlab.packet; |
| 20 | |
| 21 | import java.nio.ByteBuffer; |
| 22 | |
Jian Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 24 | import static org.onlab.packet.PacketUtils.*; |
| 25 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 26 | /** |
| 27 | * This class represents an Link Local Control header that is used in Ethernet |
| 28 | * 802.3. |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 29 | */ |
| 30 | public class LLC extends BasePacket { |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 31 | |
| 32 | public static final byte LLC_HEADER_LENGTH = 3; |
| 33 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 34 | 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 Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 72 | |
| 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 Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 92 | |
| 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 | } |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 101 | } |