Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
| 17 | package org.opencord.dhcpl2relay; |
| 18 | |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 22 | import java.util.Map; |
| 23 | import java.util.concurrent.atomic.AtomicLong; |
| 24 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 25 | /** |
| 26 | * Dhcp L2 relay event. |
| 27 | */ |
| 28 | public class DhcpL2RelayEvent extends AbstractEvent<DhcpL2RelayEvent.Type, DhcpAllocationInfo> { |
| 29 | |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 30 | public static final String GLOBAL_COUNTER = "global"; |
| 31 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 32 | private final ConnectPoint connectPoint; |
| 33 | |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 34 | private final Map.Entry<String, AtomicLong> countersEntry; |
| 35 | |
| 36 | private final String dhcpCountersTopic; |
| 37 | |
| 38 | private final String subscriberId; |
| 39 | |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 40 | /** |
| 41 | * Type of the event. |
| 42 | */ |
| 43 | public enum Type { |
| 44 | /** |
| 45 | * DHCP lease was updated. |
| 46 | */ |
| 47 | UPDATED, |
| 48 | |
| 49 | /** |
| 50 | * DHCP lease was removed. |
| 51 | */ |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 52 | REMOVED, |
| 53 | |
| 54 | /** |
| 55 | * DHCP stats update. |
| 56 | */ |
| 57 | STATS_UPDATE |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new event used for STATS. |
| 62 | * |
| 63 | * @param type type of the event |
| 64 | * @param allocationInfo DHCP allocation info |
| 65 | * @param connectPoint connect point the client is on |
| 66 | * @param countersEntry an entry that represents the counters (used for STATS events) |
| 67 | * @param dhcpCountersTopic Kafka topic where the dhcp counters are published |
| 68 | * @param subscriberId the subscriber identifier information |
| 69 | */ |
| 70 | public DhcpL2RelayEvent(Type type, DhcpAllocationInfo allocationInfo, ConnectPoint connectPoint, |
| 71 | Map.Entry<String, AtomicLong> countersEntry, |
| 72 | String dhcpCountersTopic, String subscriberId) { |
| 73 | super(type, allocationInfo); |
| 74 | this.connectPoint = connectPoint; |
| 75 | this.countersEntry = countersEntry; |
| 76 | this.dhcpCountersTopic = dhcpCountersTopic; |
| 77 | this.subscriberId = subscriberId; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Creates a new event. |
| 82 | * |
| 83 | * @param type type of the event |
| 84 | * @param allocationInfo DHCP allocation info |
| 85 | * @param connectPoint connect point the client is on |
| 86 | */ |
| 87 | public DhcpL2RelayEvent(Type type, DhcpAllocationInfo allocationInfo, ConnectPoint connectPoint) { |
| 88 | super(type, allocationInfo); |
| 89 | this.connectPoint = connectPoint; |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 90 | this.countersEntry = null; |
| 91 | this.dhcpCountersTopic = null; |
| 92 | this.subscriberId = null; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Gets the DHCP client connect point. |
| 97 | * |
| 98 | * @return connect point |
| 99 | */ |
| 100 | public ConnectPoint connectPoint() { |
| 101 | return connectPoint; |
| 102 | } |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Gets the counters map entry. |
| 106 | * |
| 107 | * @return counters map entry |
| 108 | */ |
| 109 | public Map.Entry<String, AtomicLong> getCountersEntry() { |
| 110 | return countersEntry; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Gets the Kafka topic where the dhcp counters are published. |
| 115 | * |
| 116 | * @return the dhcp kafka topic |
| 117 | */ |
| 118 | public String getDhcpCountersTopic() { |
| 119 | return dhcpCountersTopic; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Gets the subscriber identifier information. |
| 124 | * |
| 125 | * @return the Id from subscriber |
| 126 | */ |
| 127 | public String getSubscriberId() { |
| 128 | return subscriberId; |
| 129 | } |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 130 | } |