Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.dhcpl2relay; |
| 17 | |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 18 | import java.time.Instant; |
| 19 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 20 | import org.onlab.packet.DHCP; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.MacAddress; |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 24 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 25 | |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 26 | /** |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 27 | * Information about DHCP Allocations. |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 28 | */ |
| 29 | public class DhcpAllocationInfo { |
| 30 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 31 | private ConnectPoint location; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 32 | private String circuitId; |
| 33 | private MacAddress macAddress; |
| 34 | private IpAddress ip; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 35 | private Instant allocationTime; |
| 36 | private DHCP.MsgType type; |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 37 | private String subscriberId; |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 38 | private VlanId vlanId; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 39 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 40 | /** |
| 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 Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 48 | * @param vlanId VLAN id of subscriber or service |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 49 | * @param subscriberId Sadis ID of a subscriber |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 50 | */ |
| 51 | public DhcpAllocationInfo(ConnectPoint location, DHCP.MsgType type, |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 52 | String circuitId, MacAddress macAddress, |
| 53 | IpAddress ip, VlanId vlanId, |
| 54 | String subscriberId) { |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 55 | this.location = location; |
| 56 | this.type = type; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 57 | this.circuitId = circuitId; |
| 58 | this.macAddress = macAddress; |
| 59 | this.ip = ip; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 60 | this.allocationTime = Instant.now(); |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 61 | this.vlanId = vlanId; |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 62 | this.subscriberId = subscriberId; |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 65 | /** |
| 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 Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 88 | public String circuitId() { |
| 89 | return circuitId; |
| 90 | } |
| 91 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 92 | /** |
| 93 | * MAC address of client. |
| 94 | * |
| 95 | * @return mac address |
| 96 | */ |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 97 | public MacAddress macAddress() { |
| 98 | return macAddress; |
| 99 | } |
| 100 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 101 | /** |
| 102 | * IP address of client if it has one. |
| 103 | * |
| 104 | * @return client IP |
| 105 | */ |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 106 | public IpAddress ipAddress() { |
| 107 | return ip; |
| 108 | } |
| 109 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 110 | /** |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 111 | * VLAN id of client or service. |
| 112 | * |
| 113 | * @return vlan id |
| 114 | */ |
| 115 | public VlanId vlanId() { |
| 116 | return vlanId; |
| 117 | } |
| 118 | |
| 119 | /** |
Matteo Scandolo | 64bba8c | 2020-08-19 11:50:33 -0700 | [diff] [blame] | 120 | * SubscriberId of client if it has one. |
| 121 | * |
| 122 | * @return SubscriberId |
| 123 | */ |
| 124 | public String subscriberId() { |
| 125 | return subscriberId; |
| 126 | } |
| 127 | |
| 128 | /** |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 129 | * Timestamp when the last DHCP message was seen. |
| 130 | * |
| 131 | * @return time |
| 132 | */ |
| 133 | public Instant allocationTime() { |
Amit Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 134 | return allocationTime; |
| 135 | } |
Saurav Das | bd5ce9c | 2020-09-04 18:46:45 -0700 | [diff] [blame] | 136 | |
| 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 Ghosh | a17354e | 2017-08-23 12:56:04 +0100 | [diff] [blame] | 150 | } |