blob: 1e05637644bcdf1086478aebdb6e4d11986dce84 [file] [log] [blame]
Tunahan Sezen03e55272020-04-18 09:18:53 +00001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
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
7 *
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.
15 */
16package org.opencord.maclearner.app.impl;
17
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.VlanId;
23import org.onosproject.net.ConnectPoint;
24
25import java.util.Optional;
26
27import static org.junit.Assert.assertEquals;
28import static org.junit.Assert.assertTrue;
29
30/**
31 * Set of tests of the Mac Learner ONOS application component.
32 */
33public class MacLearnerManagerTest extends TestBaseMacLearner {
34
35 @Before
36 public void setUp() {
37 setUpApp();
38 }
39
40 @After
41 public void tearDown() {
42 this.macLearnerManager.deactivate();
43 }
44
45 private static final MacAddress CLIENT_MAC = MacAddress.valueOf("00:00:00:00:00:01");
46 private static final VlanId CLIENT_VLAN = VlanId.vlanId("100");
47 private static final VlanId CLIENT_QINQ_VLAN = VlanId.vlanId("200");
48 private static final ConnectPoint CLIENT_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/1");
49
50 @Test
51 public void testSingleTagDhcpPacket() {
52 packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC,
53 CLIENT_VLAN,
54 VlanId.NONE,
55 CLIENT_CP));
56 Optional<MacAddress> macAddress = macLearnerManager.getMacMapping(CLIENT_CP.deviceId(),
57 CLIENT_CP.port(), CLIENT_VLAN);
58 assertTrue(macAddress.isPresent());
59 assertEquals(CLIENT_MAC, macAddress.get());
60 }
61
62 @Test
63 public void testDoubleTagDhcpPacket() {
64 packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC,
65 CLIENT_VLAN,
66 CLIENT_QINQ_VLAN,
67 CLIENT_CP));
68 Optional<MacAddress> macAddress = macLearnerManager.getMacMapping(CLIENT_CP.deviceId(),
69 CLIENT_CP.port(), CLIENT_QINQ_VLAN);
70 assertTrue(macAddress.isPresent());
71 assertEquals(CLIENT_MAC, macAddress.get());
72 }
73
74}