blob: de715f1441ac68effd57ac5e399151e896e65f22 [file] [log] [blame]
Tunahan Sezen03e55272020-04-18 09:18:53 +00001/*
Joey Armstrong53fcac22023-01-11 13:25:01 -05002 * Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Tunahan Sezen03e55272020-04-18 09:18:53 +00003 *
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.api;
17
18import org.apache.commons.lang.builder.ToStringBuilder;
19import org.onlab.packet.MacAddress;
20import org.onlab.packet.VlanId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23
24/**
25 * Default Mac Learner object model implementation.
26 */
27public class DefaultMacLearner implements MacLearner {
28
29 private MacLearnerKey macLearnerKey;
30 private MacAddress macAddress;
31
32 public static final String DEVICE_ID_FN = "deviceId";
33 public static final String PORT_NUMBER_FN = "portNumber";
34 public static final String VLAN_ID_FN = "vlanId";
35 public static final String MAC_ADDRESS_FN = "macAddress";
36
37 @Override
38 public DeviceId deviceId() {
39 return macLearnerKey.getDeviceId();
40 }
41
42 @Override
43 public PortNumber portNumber() {
44 return macLearnerKey.getPortNumber();
45 }
46
47 @Override
48 public VlanId vlanId() {
49 return macLearnerKey.getVlanId();
50 }
51
52 @Override
53 public MacAddress macAddress() {
54 return macAddress;
55 }
56
57 public DefaultMacLearner(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, MacAddress macAddress) {
58 this.macLearnerKey = new MacLearnerKey(deviceId, portNumber, vlanId);
59 this.macAddress = macAddress;
60 }
61
62 @Override
63 public String toString() {
64 return new ToStringBuilder(this)
65 .append(DEVICE_ID_FN, deviceId())
66 .append(PORT_NUMBER_FN, portNumber())
67 .append(VLAN_ID_FN, vlanId())
68 .append(MAC_ADDRESS_FN, macAddress())
69 .toString();
70 }
71
72}