blob: 377dddec84d17e57165029822f7cd14d756db6b1 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
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 */
16package org.onosproject.incubator.net.l2monitoring.cfm;
17
18import java.time.Duration;
19
20import org.onlab.packet.MacAddress;
21import org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv.SenderIdTlvType;
22import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
23import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
24
25/**
26 * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry}.
27 */
28public class DefaultRemoteMepEntry implements RemoteMepEntry {
29
30 private final MepId remoteMepId;
31 private final RemoteMepState state;
32 private final Duration failedOrOkTime;
33 private final MacAddress macAddress;
34 private final boolean rdi;
35 private final PortStatusTlvType portStatusTlvType;
36 private final InterfaceStatusTlvType interfaceStatusTlvType;
37 private final SenderIdTlvType senderIdTlvType;
38
39 protected DefaultRemoteMepEntry(DefaultRemoteMepEntryBuilder rmepBuilder) {
40 this.remoteMepId = rmepBuilder.remoteMepId;
41 this.state = rmepBuilder.state;
42 this.failedOrOkTime = rmepBuilder.failedOrOkTime;
43 this.macAddress = rmepBuilder.macAddress;
44 this.rdi = rmepBuilder.rdi;
45 this.portStatusTlvType = rmepBuilder.portStatusTlvType;
46 this.interfaceStatusTlvType = rmepBuilder.interfaceStatusTlvType;
47 this.senderIdTlvType = rmepBuilder.senderIdTlvType;
48 }
49
50 @Override
51 public MepId remoteMepId() {
52 return this.remoteMepId;
53 }
54
55 @Override
56 public RemoteMepState state() {
57 return this.state;
58 }
59
60 @Override
61 public Duration failedOrOkTime() {
62 return failedOrOkTime;
63 }
64
65 @Override
66 public MacAddress macAddress() {
67 return macAddress;
68 }
69
70 @Override
71 public boolean rdi() {
72 return rdi;
73 }
74
75 @Override
76 public PortStatusTlvType portStatusTlvType() {
77 return portStatusTlvType;
78 }
79
80 @Override
81 public InterfaceStatusTlvType interfaceStatusTlvType() {
82 return interfaceStatusTlvType;
83 }
84
85 @Override
86 public SenderIdTlvType senderIdTlvType() {
87 return senderIdTlvType;
88 }
89
90 public static RemoteMepEntryBuilder builder(
91 MepId remoteMepId, RemoteMepState state) throws CfmConfigException {
92 return new DefaultRemoteMepEntryBuilder(remoteMepId, state);
93 }
94
95 private static class DefaultRemoteMepEntryBuilder implements RemoteMepEntryBuilder {
96 private final MepId remoteMepId;
97 private final RemoteMepState state;
98 private Duration failedOrOkTime;
99 private MacAddress macAddress;
100 private boolean rdi;
101 private PortStatusTlvType portStatusTlvType;
102 private InterfaceStatusTlvType interfaceStatusTlvType;
103 private SenderIdTlvType senderIdTlvType;
104
105 protected DefaultRemoteMepEntryBuilder(MepId remoteMepId,
106 RemoteMepState state) throws CfmConfigException {
107 if (remoteMepId == null) {
108 throw new CfmConfigException("remoteMepId is null");
109 } else if (state == null) {
110 throw new CfmConfigException("state is null");
111 }
112 this.remoteMepId = remoteMepId;
113 this.state = state;
114 }
115
116 @Override
117 public RemoteMepEntryBuilder failedOrOkTime(Duration failedOrOkTime) {
118 this.failedOrOkTime = failedOrOkTime;
119 return this;
120 }
121
122 @Override
123 public RemoteMepEntryBuilder macAddress(MacAddress macAddress) {
124 this.macAddress = macAddress;
125 return this;
126 }
127
128 @Override
129 public RemoteMepEntryBuilder rdi(boolean rdi) {
130 this.rdi = rdi;
131 return this;
132 }
133
134 @Override
135 public RemoteMepEntryBuilder portStatusTlvType(PortStatusTlvType portStatusTlvType) {
136 this.portStatusTlvType = portStatusTlvType;
137 return this;
138 }
139
140 @Override
141 public RemoteMepEntryBuilder interfaceStatusTlvType(
142 InterfaceStatusTlvType interfaceStatusTlvType) {
143 this.interfaceStatusTlvType = interfaceStatusTlvType;
144 return this;
145 }
146
147 @Override
148 public RemoteMepEntryBuilder senderIdTlvType(
149 SenderIdTlvType senderIdTlvType) {
150 this.senderIdTlvType = senderIdTlvType;
151 return this;
152 }
153
154 @Override
155 public RemoteMepEntry build() {
156 return new DefaultRemoteMepEntry(this);
157 }
158 }
159}