blob: 3c0825b7d78d393b4cabd0a7846ea1b8f846c310 [file] [log] [blame]
Amit Ghosha17354e2017-08-23 12:56:04 +01001/*
Joey Armstrong7e08d2a2022-12-30 12:25:42 -05002 * Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Amit Ghosha17354e2017-08-23 12:56:04 +01003 *
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.dhcpl2relay;
17
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070018import java.time.Instant;
19
Jonathan Hartc36c9552018-07-31 15:07:53 -040020import org.onlab.packet.DHCP;
Amit Ghosha17354e2017-08-23 12:56:04 +010021import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070023import org.onlab.packet.VlanId;
Jonathan Hartc36c9552018-07-31 15:07:53 -040024import org.onosproject.net.ConnectPoint;
Amit Ghosha17354e2017-08-23 12:56:04 +010025
Amit Ghosha17354e2017-08-23 12:56:04 +010026/**
Jonathan Hartc36c9552018-07-31 15:07:53 -040027 * Information about DHCP Allocations.
Amit Ghosha17354e2017-08-23 12:56:04 +010028 */
29public class DhcpAllocationInfo {
30
Jonathan Hartc36c9552018-07-31 15:07:53 -040031 private ConnectPoint location;
Amit Ghosha17354e2017-08-23 12:56:04 +010032 private String circuitId;
33 private MacAddress macAddress;
34 private IpAddress ip;
Jonathan Hartc36c9552018-07-31 15:07:53 -040035 private Instant allocationTime;
36 private DHCP.MsgType type;
Matteo Scandolo64bba8c2020-08-19 11:50:33 -070037 private String subscriberId;
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070038 private VlanId vlanId;
Amit Ghosha17354e2017-08-23 12:56:04 +010039
Jonathan Hartc36c9552018-07-31 15:07:53 -040040 /**
41 * Creates a new DHCP allocation info record.
42 *
43 * @param location connect point the requestor was seen on
44 * @param type last known message type
45 * @param circuitId option 82 information
46 * @param macAddress MAC address of client
47 * @param ip IP of client if allocated
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070048 * @param vlanId VLAN id of subscriber or service
Matteo Scandolo64bba8c2020-08-19 11:50:33 -070049 * @param subscriberId Sadis ID of a subscriber
Jonathan Hartc36c9552018-07-31 15:07:53 -040050 */
51 public DhcpAllocationInfo(ConnectPoint location, DHCP.MsgType type,
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070052 String circuitId, MacAddress macAddress,
53 IpAddress ip, VlanId vlanId,
54 String subscriberId) {
Jonathan Hartc36c9552018-07-31 15:07:53 -040055 this.location = location;
56 this.type = type;
Amit Ghosha17354e2017-08-23 12:56:04 +010057 this.circuitId = circuitId;
58 this.macAddress = macAddress;
59 this.ip = ip;
Jonathan Hartc36c9552018-07-31 15:07:53 -040060 this.allocationTime = Instant.now();
Saurav Dasbd5ce9c2020-09-04 18:46:45 -070061 this.vlanId = vlanId;
Matteo Scandolo64bba8c2020-08-19 11:50:33 -070062 this.subscriberId = subscriberId;
Amit Ghosha17354e2017-08-23 12:56:04 +010063 }
64
Jonathan Hartc36c9552018-07-31 15:07:53 -040065 /**
66 * Location the requestor was seen on.
67 *
68 * @return connect point
69 */
70 public ConnectPoint location() {
71 return location;
72 }
73
74 /**
75 * Last seen message type of the DHCP exchange.
76 *
77 * @return DHCP message type
78 */
79 public DHCP.MsgType type() {
80 return type;
81 }
82
83 /**
84 * Option 82 information.
85 *
86 * @return circuit ID
87 */
Amit Ghosha17354e2017-08-23 12:56:04 +010088 public String circuitId() {
89 return circuitId;
90 }
91
Jonathan Hartc36c9552018-07-31 15:07:53 -040092 /**
93 * MAC address of client.
94 *
95 * @return mac address
96 */
Amit Ghosha17354e2017-08-23 12:56:04 +010097 public MacAddress macAddress() {
98 return macAddress;
99 }
100
Jonathan Hartc36c9552018-07-31 15:07:53 -0400101 /**
102 * IP address of client if it has one.
103 *
104 * @return client IP
105 */
Amit Ghosha17354e2017-08-23 12:56:04 +0100106 public IpAddress ipAddress() {
107 return ip;
108 }
109
Jonathan Hartc36c9552018-07-31 15:07:53 -0400110 /**
Saurav Dasbd5ce9c2020-09-04 18:46:45 -0700111 * VLAN id of client or service.
112 *
113 * @return vlan id
114 */
115 public VlanId vlanId() {
116 return vlanId;
117 }
118
119 /**
Matteo Scandolo64bba8c2020-08-19 11:50:33 -0700120 * SubscriberId of client if it has one.
121 *
122 * @return SubscriberId
123 */
124 public String subscriberId() {
125 return subscriberId;
126 }
127
128 /**
Jonathan Hartc36c9552018-07-31 15:07:53 -0400129 * Timestamp when the last DHCP message was seen.
130 *
131 * @return time
132 */
133 public Instant allocationTime() {
Amit Ghosha17354e2017-08-23 12:56:04 +0100134 return allocationTime;
135 }
Saurav Dasbd5ce9c2020-09-04 18:46:45 -0700136
137 @Override
138 public String toString() {
139 return com.google.common.base.MoreObjects.toStringHelper(this)
140 .add("subscriberId", subscriberId)
141 .add("location", location)
142 .add("state", type)
143 .add("macAddress", macAddress)
144 .add("vlanId", vlanId)
145 .add("circuitId", circuitId)
146 .add("allocatedIP", ip)
147 .add("timestamp", allocationTime)
148 .toString();
149 }
Amit Ghosha17354e2017-08-23 12:56:04 +0100150}