Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [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.onosproject.incubator.net.l2monitoring.cfm.service; |
| 17 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.util.Tools; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 20 | import org.onosproject.event.AbstractEvent; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 21 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 24 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 25 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 26 | import java.util.Optional; |
| 27 | |
| 28 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 29 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Event related to the maintenance of CFM MDs. |
| 32 | */ |
| 33 | public class MdEvent extends AbstractEvent<MdEvent.Type, MdId> { |
| 34 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 35 | private MaIdShort maId; |
| 36 | private MaintenanceDomain oldMd; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 37 | /** |
| 38 | * MD Event types supported. |
| 39 | */ |
| 40 | public enum Type { |
| 41 | MD_ADDED, |
| 42 | MD_REMOVED, |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 43 | MD_UPDATED, |
| 44 | MA_ADDED, |
| 45 | MA_REMOVED |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public MdEvent(Type type, MdId mdId) { |
| 49 | super(type, mdId); |
| 50 | } |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame^] | 51 | |
| 52 | /** |
| 53 | * Constructor that allows the MD to be held in the event. |
| 54 | * This is useful if the MD had been deleted - it will be the only way of |
| 55 | * retrieving some of its attributes |
| 56 | * @param type The type of the event |
| 57 | * @param mdId The ID of the MD |
| 58 | * @param md The whole MD |
| 59 | * @throws CfmConfigException if there's a problem copying MD |
| 60 | */ |
| 61 | public MdEvent(Type type, MdId mdId, MaintenanceDomain md) throws CfmConfigException { |
| 62 | super(type, mdId); |
| 63 | this.oldMd = DefaultMaintenanceDomain.builder(md).build(); |
| 64 | } |
| 65 | |
| 66 | public MdEvent(Type type, MdId mdId, MaintenanceDomain md, MaIdShort maId) |
| 67 | throws CfmConfigException { |
| 68 | super(type, mdId); |
| 69 | this.maId = maId; |
| 70 | this.oldMd = DefaultMaintenanceDomain.builder(md).build(); |
| 71 | } |
| 72 | |
| 73 | public Optional<MaIdShort> maId() { |
| 74 | return maId == null ? Optional.empty() : Optional.of(maId); |
| 75 | } |
| 76 | |
| 77 | public Optional<MaintenanceDomain> md() { |
| 78 | return oldMd == null ? Optional.empty() : Optional.of(oldMd); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public String toString() { |
| 83 | MoreObjects.ToStringHelper helper = toStringHelper(this) |
| 84 | .add("time", Tools.defaultOffsetDataTime(time())) |
| 85 | .add("type", type()) |
| 86 | .add("subject", subject()); |
| 87 | if (maId != null) { |
| 88 | helper = helper.add("subject2", maId); |
| 89 | } |
| 90 | return helper.toString(); |
| 91 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 92 | } |