blob: 66cec51ea234c5ef6a0d666d890d508a74f8297c [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -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
Thomas Vachuska24c849c2014-10-27 09:53:05 -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 */
Ayaka Koshibe16698a32014-09-13 22:19:02 -070016package org.onlab.packet;
17
18import static org.junit.Assert.assertEquals;
19
20import org.junit.Test;
21
22import com.google.common.testing.EqualsTester;
23
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070024public class VlanIdTest {
Ayaka Koshibe16698a32014-09-13 22:19:02 -070025
26 @Test
27 public void testEquality() {
28
Luca Prete283a9622016-03-29 16:12:20 -070029 VlanId vlan1 = VlanId.vlanId("None");
30 VlanId vlan2 = VlanId.vlanId((short) -1);
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070031 VlanId vlan3 = VlanId.vlanId((short) 100);
Luca Prete283a9622016-03-29 16:12:20 -070032 VlanId vlan4 = VlanId.vlanId((short) 100);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070033
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070034 new EqualsTester().addEqualityGroup(VlanId.vlanId(), vlan1)
Luca Prete283a9622016-03-29 16:12:20 -070035 .addEqualityGroup(vlan1, vlan2)
36 .addEqualityGroup(vlan3, vlan4)
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070037 .addEqualityGroup(VlanId.vlanId((short) 10));
Ayaka Koshibe16698a32014-09-13 22:19:02 -070038
39 }
40
41 @Test
42 public void basics() {
43 // purposefully create UNTAGGED VLAN
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070044 VlanId vlan1 = VlanId.vlanId((short) 10);
45 VlanId vlan2 = VlanId.vlanId((short) -1);
Luca Prete283a9622016-03-29 16:12:20 -070046 VlanId vlan3 = VlanId.vlanId("None");
Ayaka Koshibe16698a32014-09-13 22:19:02 -070047
48 assertEquals("incorrect VLAN value", 10, vlan1.toShort());
Luca Prete283a9622016-03-29 16:12:20 -070049 assertEquals("invalid untagged value", VlanId.UNTAGGED,
50 vlan2.toShort(), vlan3.toShort());
51
Ayaka Koshibe16698a32014-09-13 22:19:02 -070052 }
53
54 @Test(expected = IllegalArgumentException.class)
55 public void testIllicitVLAN() {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070056 VlanId.vlanId((short) 5000);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070057 }
58}