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.drivers.microsemi; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.time.Duration; |
| 22 | import java.util.Collection; |
| 23 | |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onlab.util.HexString; |
| 28 | import org.onosproject.drivers.microsemi.yang.MseaCfmNetconfService; |
| 29 | import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil; |
| 30 | import org.onosproject.incubator.net.l2monitoring.cfm.Component; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbEntry; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultRemoteMepEntry; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection; |
| 38 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 39 | import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry; |
| 40 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate; |
| 41 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLbEntry.MepLbEntryBuilder; |
| 42 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate; |
| 43 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry; |
| 44 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType; |
| 45 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType; |
| 46 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepEntryBuilder; |
| 47 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState; |
| 48 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 49 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 50 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 51 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName; |
| 52 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint; |
| 53 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone; |
| 54 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 55 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 56 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 57 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable; |
| 58 | import org.onosproject.net.DeviceId; |
| 59 | import org.onosproject.net.PortNumber; |
| 60 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 61 | import org.onosproject.netconf.DatastoreId; |
| 62 | import org.onosproject.netconf.NetconfController; |
| 63 | import org.onosproject.netconf.NetconfException; |
| 64 | import org.onosproject.netconf.NetconfSession; |
| 65 | import org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes.DomainName; |
| 66 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfm; |
| 67 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfmOpParam; |
| 68 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.DefaultMefCfm; |
| 69 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.MefCfm; |
| 70 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.AbortLoopbackInput; |
| 71 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.DefaultAbortLoopbackInput; |
| 72 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.faultalarmdefectbitstype.Bits; |
| 73 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.DefaultMaintenanceDomain; |
| 74 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.DefaultMaintenanceAssociation; |
| 75 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo; |
| 76 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.CcmIntervalEnum; |
| 77 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.ComponentList; |
| 78 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.DefaultComponentList; |
| 79 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.DefaultMaintenanceAssociationEndPoint; |
| 80 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo; |
| 81 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaintenanceAssociationEndPoint; |
| 82 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.componentlist.TagTypeEnum; |
| 83 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.ContinuityCheck; |
| 84 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultContinuityCheck; |
| 85 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.InterfaceEnum; |
| 86 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultMacAddressAndUint; |
| 87 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameCharacterString; |
| 88 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameDomainName; |
| 89 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameNone; |
| 90 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.namedomainname.NameDomainNameUnion; |
| 91 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.remotemepstatetype.RemoteMepStateTypeEnum; |
| 92 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMacAddress; |
| 93 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMepId; |
| 94 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.DefaultTransmitLoopbackInput; |
| 95 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.TransmitLoopbackInput; |
| 96 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.transmitloopbackinput.DefaultTargetAddress; |
| 97 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.transmitloopbackinput.TargetAddress; |
| 98 | import org.onosproject.yang.gen.v1.mseasoamfm.rev20160229.mseasoamfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.AugmentedMseaCfmMaintenanceAssociationEndPoint; |
| 99 | import org.onosproject.yang.gen.v1.mseasoamfm.rev20160229.mseasoamfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint; |
| 100 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45; |
| 101 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MacAddressAndUintStr; |
| 102 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MdLevelType; |
| 103 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MepIdType; |
| 104 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.PriorityType; |
| 105 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.VlanIdType; |
| 106 | import org.slf4j.Logger; |
| 107 | |
| 108 | /** |
| 109 | * Implementation of CfmMepProgrammable for Microsemi EA1000. |
| 110 | */ |
| 111 | public class EA1000CfmMepProgrammable extends AbstractHandlerBehaviour |
| 112 | implements CfmMepProgrammable { |
| 113 | |
| 114 | private static final int NUMERIC_ID_MAX = 64; |
| 115 | private static final int REMOTEMEPLIST_MIN_COUNT = 2; |
| 116 | private static final int REMOTEMEPLIST_MAX_COUNT = 9; |
| 117 | private static final int COMPONENT_LIST_SIZE = 1; |
| 118 | private static final int VIDLIST_SIZE_MIN = 1; |
| 119 | private static final int MEP_PORT_MIN = 0; |
| 120 | private static final int MEP_PORT_MAX = 1; |
| 121 | private final Logger log = getLogger(getClass()); |
| 122 | |
| 123 | public EA1000CfmMepProgrammable() { |
| 124 | log.debug("Loaded handler behaviour EA1000CfmMepProgrammable"); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public boolean createMep(MdId mdName, MaIdShort maName, Mep mep) |
| 129 | throws CfmConfigException { |
| 130 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 131 | NetconfSession session = controller.getDevicesMap() |
| 132 | .get(handler().data().deviceId()).getSession(); |
| 133 | MseaCfmNetconfService mseaCfmService = |
| 134 | checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 135 | |
| 136 | MaintenanceAssociationEndPoint yangMep = buildYangMepFromApiMep(mep); |
| 137 | |
| 138 | CfmMdService cfmMdService = checkNotNull(handler().get(CfmMdService.class)); |
| 139 | MaintenanceDomain md = cfmMdService.getMaintenanceDomain(mdName).get(); |
| 140 | MaintenanceAssociation ma = cfmMdService.getMaintenanceAssociation(mdName, maName).get(); |
| 141 | |
| 142 | if (!ma.remoteMepIdList().contains(mep.mepId())) { |
| 143 | throw new CfmConfigException("Mep Id " + mep.mepId() + |
| 144 | " is not present in the remote Mep list for MA " + ma.maId() + |
| 145 | ". This is required for EA1000."); |
| 146 | } else if (md.mdNumericId() <= 0 || md.mdNumericId() > NUMERIC_ID_MAX) { |
| 147 | throw new CfmConfigException("Numeric id of MD " + mdName + " must" |
| 148 | + " be between 1 and 64 inclusive for EA1000"); |
| 149 | } else if (ma.maNumericId() <= 0 || ma.maNumericId() > NUMERIC_ID_MAX) { |
| 150 | throw new CfmConfigException("Numeric id of MA " + maName + " must" |
| 151 | + " be between 1 and 64 inclusive for EA1000"); |
| 152 | } |
| 153 | |
| 154 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain |
| 155 | .MaintenanceAssociation yangMa = buildYangMaFromApiMa(ma); |
| 156 | yangMa.addToMaintenanceAssociationEndPoint(yangMep); |
| 157 | |
| 158 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm |
| 159 | .mefcfm.MaintenanceDomain yangMd = buildYangMdFromApiMd(md); |
| 160 | yangMd.addToMaintenanceAssociation(yangMa); |
| 161 | |
| 162 | MefCfm mefCfm = new DefaultMefCfm(); |
| 163 | mefCfm.addToMaintenanceDomain(yangMd); |
| 164 | |
| 165 | MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam(); |
| 166 | mseaCfmOpParam.mefCfm(mefCfm); |
| 167 | try { |
| 168 | mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING); |
| 169 | log.info("Created MEP {} on device {}", mdName + "/" + maName + |
| 170 | "/" + mep.mepId(), handler().data().deviceId()); |
| 171 | return true; |
| 172 | } catch (NetconfException e) { |
| 173 | log.error("Unable to create MEP {}/{}/{} on device {}", |
| 174 | mdName, maName, mep.mepId(), handler().data().deviceId()); |
| 175 | throw new CfmConfigException("Unable to create MEP :" + e.getMessage()); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName) throws CfmConfigException { |
| 181 | throw new UnsupportedOperationException("Not yet implemented"); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId) |
| 186 | throws CfmConfigException { |
| 187 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 188 | if (handler().data().deviceId() == null) { |
| 189 | throw new CfmConfigException("Device is not ready - connecting or " |
| 190 | + "disconnected for MEP " + mdName + "/" + maName + "/" + mepId); |
| 191 | } |
| 192 | NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); |
| 193 | MseaCfmNetconfService mseaCfmService = checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 194 | |
| 195 | try { |
| 196 | MseaCfm mseacfm = |
| 197 | mseaCfmService.getMepFull(mdName, maName, mepId, session); |
| 198 | for (org.onosproject.yang.gen.v1.mseacfm.rev20160229. |
| 199 | mseacfm.mefcfm.MaintenanceDomain replyMd:mseacfm.mefCfm().maintenanceDomain()) { |
| 200 | for (org.onosproject.yang.gen.v1.mseacfm.rev20160229. |
| 201 | mseacfm.mefcfm.maintenancedomain. |
| 202 | MaintenanceAssociation replyMa:replyMd.maintenanceAssociation()) { |
| 203 | for (MaintenanceAssociationEndPoint replyMep:replyMa.maintenanceAssociationEndPoint()) { |
| 204 | return buildApiMepEntryFromYangMep(replyMep, handler().data().deviceId(), mdName, maName); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | log.warn("Mep " + mepId + " not found on device " + handler().data().deviceId()); |
| 209 | return null; |
| 210 | } catch (NetconfException e) { |
| 211 | log.error("Unable to get MEP {}/{}/{} on device {}", |
| 212 | mdName, maName, mepId, handler().data().deviceId()); |
| 213 | throw new CfmConfigException("Unable to create MEP :" + e.getMessage()); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException { |
| 219 | |
| 220 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 221 | NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); |
| 222 | MseaCfmNetconfService mseaCfmService = checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 223 | |
| 224 | MaintenanceAssociationEndPoint mep = |
| 225 | new DefaultMaintenanceAssociationEndPoint(); |
| 226 | mep.mepIdentifier(MepIdType.of(mepId.id())); |
| 227 | |
| 228 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain |
| 229 | .MaintenanceAssociation yangMa = new DefaultMaintenanceAssociation(); |
| 230 | yangMa.maNameAndTypeCombo(MaNameUtil.getYangMaNameFromApiMaId(maName)); |
| 231 | yangMa.addToMaintenanceAssociationEndPoint(mep); |
| 232 | |
| 233 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain yangMd = |
| 234 | new DefaultMaintenanceDomain(); |
| 235 | yangMd.mdNameAndTypeCombo(getYangMdNameFromApiMdId(mdName)); |
| 236 | yangMd.addToMaintenanceAssociation(yangMa); |
| 237 | |
| 238 | MefCfm mefCfm = new DefaultMefCfm(); |
| 239 | mefCfm.addToMaintenanceDomain(yangMd); |
| 240 | |
| 241 | MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam(); |
| 242 | mseaCfmOpParam.mefCfm(mefCfm); |
| 243 | |
| 244 | try { |
| 245 | mseaCfmService.deleteMseaMep(mseaCfmOpParam, session, DatastoreId.RUNNING); |
| 246 | log.info("Deleted MEP {} on device {}", mdName + "/" + maName + |
| 247 | "/" + mepId, handler().data().deviceId()); |
| 248 | return true; |
| 249 | } catch (NetconfException e) { |
| 250 | log.error("Unable to delete MEP {}/{}/{} on device {}", |
| 251 | mdName, maName, mepId, handler().data().deviceId()); |
| 252 | throw new CfmConfigException("Unable to delete MEP :" + e.getMessage()); |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void transmitLoopback(MdId mdName, MaIdShort maName, MepId mepId, |
| 259 | MepLbCreate lbCreate) throws CfmConfigException { |
| 260 | NetconfController controller = |
| 261 | checkNotNull(handler().get(NetconfController.class)); |
| 262 | NetconfSession session = controller.getDevicesMap() |
| 263 | .get(handler().data().deviceId()).getSession(); |
| 264 | MseaCfmNetconfService mseaCfmService = |
| 265 | checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 266 | CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class)); |
| 267 | |
| 268 | Short mdNumericId = mdService.getMaintenanceDomain(mdName).get().mdNumericId(); |
| 269 | Short maNumericId = |
| 270 | mdService.getMaintenanceAssociation(mdName, maName).get().maNumericId(); |
| 271 | |
| 272 | TransmitLoopbackInput lb = new DefaultTransmitLoopbackInput(); |
| 273 | lb.maintenanceDomain(mdNumericId); |
| 274 | lb.maintenanceAssociation(maNumericId); |
| 275 | lb.maintenanceAssociationEndPoint(mepId.id()); |
| 276 | if (lbCreate.numberMessages() != null) { |
| 277 | lb.numberOfMessages(lbCreate.numberMessages()); |
| 278 | } |
| 279 | if (lbCreate.vlanDropEligible() != null) { |
| 280 | lb.vlanDropEligible(lbCreate.vlanDropEligible()); |
| 281 | } |
| 282 | |
| 283 | if (lbCreate.remoteMepId() != null) { |
| 284 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype |
| 285 | .MepId yangMepId = new DefaultMepId(); |
| 286 | yangMepId.mepId(MepIdType.of(lbCreate.remoteMepId().id())); |
| 287 | TargetAddress ta = new DefaultTargetAddress(); |
| 288 | ta.addressType(yangMepId); |
| 289 | lb.targetAddress(ta); |
| 290 | } else if (lbCreate.remoteMepAddress() != null) { |
| 291 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype |
| 292 | .MacAddress yangMacAddress = new DefaultMacAddress(); |
| 293 | yangMacAddress.macAddress( |
| 294 | org.onosproject.yang.gen.v1.ietfyangtypes.rev20130715.ietfyangtypes |
| 295 | .MacAddress.of(lbCreate.remoteMepAddress().toString())); |
| 296 | TargetAddress ta = new DefaultTargetAddress(); |
| 297 | ta.addressType(yangMacAddress); |
| 298 | lb.targetAddress(ta); |
| 299 | } else { |
| 300 | throw new CfmConfigException("Either a remote MEP ID or Remote MEP " |
| 301 | + "MacAddress must be specified when calling Transmit Loopback"); |
| 302 | } |
| 303 | |
| 304 | if (lbCreate.dataTlvHex() != null && !lbCreate.dataTlvHex().isEmpty()) { |
| 305 | lb.dataTlv(HexString.fromHexString(lbCreate.dataTlvHex())); |
| 306 | } |
| 307 | if (lbCreate.vlanPriority() != null) { |
| 308 | lb.vlanPriority(PriorityType.of((short) lbCreate.vlanPriority().ordinal())); |
| 309 | } |
| 310 | |
| 311 | try { |
| 312 | mseaCfmService.transmitLoopback(lb, session); |
| 313 | log.info("Transmit Loopback called on MEP {} on device {}", |
| 314 | mdName + "/" + maName + "/" + mepId, |
| 315 | handler().data().deviceId()); |
| 316 | } catch (NetconfException e) { |
| 317 | throw new CfmConfigException(e); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void abortLoopback(MdId mdName, MaIdShort maName, MepId mepId) |
| 323 | throws CfmConfigException { |
| 324 | NetconfController controller = |
| 325 | checkNotNull(handler().get(NetconfController.class)); |
| 326 | NetconfSession session = controller.getDevicesMap() |
| 327 | .get(handler().data().deviceId()).getSession(); |
| 328 | MseaCfmNetconfService mseaCfmService = |
| 329 | checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 330 | CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class)); |
| 331 | |
| 332 | Short mdNumericId = mdService.getMaintenanceDomain(mdName).get().mdNumericId(); |
| 333 | Short maNumericId = |
| 334 | mdService.getMaintenanceAssociation(mdName, maName).get().maNumericId(); |
| 335 | |
| 336 | AbortLoopbackInput lbAbort = new DefaultAbortLoopbackInput(); |
| 337 | lbAbort.maintenanceDomain(mdNumericId); |
| 338 | lbAbort.maintenanceAssociation(maNumericId); |
| 339 | lbAbort.maintenanceAssociationEndPoint(mepId.id()); |
| 340 | |
| 341 | try { |
| 342 | mseaCfmService.abortLoopback(lbAbort, session); |
| 343 | log.info("Loopback on MEP {} on device {} aborted", |
| 344 | mdName + "/" + maName + "/" + mepId, |
| 345 | handler().data().deviceId()); |
| 346 | } catch (NetconfException e) { |
| 347 | throw new CfmConfigException(e); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public void transmitLinktrace(MdId mdName, MaIdShort maName, MepId mepId, |
| 353 | MepLtCreate ltCreate) { |
| 354 | throw new UnsupportedOperationException("Not yet implemented"); |
| 355 | } |
| 356 | |
| 357 | private org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 358 | .MaintenanceDomain buildYangMdFromApiMd(MaintenanceDomain md) |
| 359 | throws CfmConfigException { |
| 360 | MdNameAndTypeCombo mdName = getYangMdNameFromApiMdId(md.mdId()); |
| 361 | |
| 362 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 363 | .MaintenanceDomain mdYang = new DefaultMaintenanceDomain(); |
| 364 | mdYang.id(md.mdNumericId()); |
| 365 | mdYang.mdNameAndTypeCombo(mdName); |
| 366 | mdYang.mdLevel(MdLevelType.of((short) md.mdLevel().ordinal())); |
| 367 | |
| 368 | return mdYang; |
| 369 | } |
| 370 | |
| 371 | protected static MdNameAndTypeCombo getYangMdNameFromApiMdId(MdId mdId) |
| 372 | throws CfmConfigException { |
| 373 | MdNameAndTypeCombo mdName; |
| 374 | if (mdId instanceof MdIdDomainName) { |
| 375 | boolean isIpAddr = false; |
| 376 | try { |
| 377 | if (IpAddress.valueOf(mdId.mdName()) != null) { |
| 378 | isIpAddr = true; |
| 379 | } |
| 380 | } catch (IllegalArgumentException e) { |
| 381 | //continue |
| 382 | } |
| 383 | if (isIpAddr) { |
| 384 | mdName = new DefaultNameDomainName(); |
| 385 | ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion.of( |
| 386 | org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes. |
| 387 | IpAddress.fromString(mdId.mdName()))); |
| 388 | } else { |
| 389 | mdName = new DefaultNameDomainName(); |
| 390 | ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion |
| 391 | .of(DomainName.fromString(mdId.mdName()))); |
| 392 | } |
| 393 | } else if (mdId instanceof MdIdMacUint) { |
| 394 | mdName = new DefaultMacAddressAndUint(); |
| 395 | ((DefaultMacAddressAndUint) mdName).nameMacAddressAndUint(MacAddressAndUintStr.fromString(mdId.mdName())); |
| 396 | } else if (mdId instanceof MdIdNone) { |
| 397 | mdName = new DefaultNameNone(); |
| 398 | } else if (mdId instanceof MdIdCharStr) { |
| 399 | mdName = new DefaultNameCharacterString(); |
| 400 | ((DefaultNameCharacterString) mdName).name(Identifier45.fromString(mdId.mdName())); |
| 401 | } else { |
| 402 | throw new CfmConfigException("Unexpected error creating MD " + |
| 403 | mdId.getClass().getSimpleName()); |
| 404 | } |
| 405 | return mdName; |
| 406 | } |
| 407 | |
| 408 | private org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 409 | .maintenancedomain.MaintenanceAssociation buildYangMaFromApiMa( |
| 410 | MaintenanceAssociation apiMa) throws CfmConfigException { |
| 411 | |
| 412 | MaNameAndTypeCombo maName = MaNameUtil.getYangMaNameFromApiMaId(apiMa.maId()); |
| 413 | |
| 414 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain |
| 415 | .MaintenanceAssociation yamgMa = new DefaultMaintenanceAssociation(); |
| 416 | yamgMa.maNameAndTypeCombo(maName); |
| 417 | |
| 418 | if (apiMa.remoteMepIdList() == null || apiMa.remoteMepIdList().size() < REMOTEMEPLIST_MIN_COUNT |
| 419 | || apiMa.remoteMepIdList().size() > REMOTEMEPLIST_MAX_COUNT) { |
| 420 | throw new CfmConfigException("EA1000 requires between " + |
| 421 | REMOTEMEPLIST_MIN_COUNT + " and " + REMOTEMEPLIST_MAX_COUNT + |
| 422 | " remote meps in an MA"); |
| 423 | } |
| 424 | for (MepId rmep:apiMa.remoteMepIdList()) { |
| 425 | yamgMa.addToRemoteMeps(MepIdType.of(rmep.id())); |
| 426 | } |
| 427 | |
| 428 | if (apiMa.ccmInterval() != null) { |
| 429 | switch (apiMa.ccmInterval()) { |
| 430 | case INTERVAL_3MS: |
| 431 | yamgMa.ccmInterval(CcmIntervalEnum.YANGAUTOPREFIX3_3MS); |
| 432 | break; |
| 433 | case INVERVAL_10MS: |
| 434 | yamgMa.ccmInterval(CcmIntervalEnum.YANGAUTOPREFIX10MS); |
| 435 | break; |
| 436 | case INVERVAL_100MS: |
| 437 | yamgMa.ccmInterval(CcmIntervalEnum.YANGAUTOPREFIX100MS); |
| 438 | break; |
| 439 | case INTERVAL_1S: |
| 440 | yamgMa.ccmInterval(CcmIntervalEnum.YANGAUTOPREFIX1S); |
| 441 | break; |
| 442 | default: |
| 443 | throw new CfmConfigException("EA1000 only supports " |
| 444 | + "3ms, 10ms, 100ms and 1s for CCM Interval. Rejecting: " |
| 445 | + apiMa.ccmInterval().name()); |
| 446 | } |
| 447 | } |
| 448 | if (apiMa.componentList() == null || apiMa.componentList().size() != COMPONENT_LIST_SIZE) { |
| 449 | throw new CfmConfigException("EA1000 supports only 1 Component in an MA"); |
| 450 | } |
| 451 | |
| 452 | Component maComponent = apiMa.componentList().iterator().next(); |
| 453 | if (maComponent.vidList() == null || maComponent.vidList().size() < VIDLIST_SIZE_MIN) { |
| 454 | throw new CfmConfigException("EA1000 requires at least 1 VID in " |
| 455 | + "the Component of an MA"); |
| 456 | } |
| 457 | ComponentList compList = new DefaultComponentList(); |
| 458 | for (VlanId vid:maComponent.vidList()) { |
| 459 | compList.addToVid(VlanIdType.of(vid.toShort())); |
| 460 | } |
| 461 | |
| 462 | if (maComponent.tagType() != null) { |
| 463 | switch (maComponent.tagType()) { |
| 464 | case VLAN_STAG: |
| 465 | compList.tagType(TagTypeEnum.VLAN_STAG); |
| 466 | break; |
| 467 | case VLAN_CTAG: |
| 468 | compList.tagType(TagTypeEnum.VLAN_CTAG); |
| 469 | break; |
| 470 | case VLAN_NONE: |
| 471 | default: |
| 472 | compList.tagType(TagTypeEnum.VLAN_NONE); |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | yamgMa.componentList(compList); |
| 478 | yamgMa.id(apiMa.maNumericId()); |
| 479 | return yamgMa; |
| 480 | } |
| 481 | |
| 482 | private MaintenanceAssociationEndPoint buildYangMepFromApiMep(Mep mep) |
| 483 | throws CfmConfigException { |
| 484 | MaintenanceAssociationEndPoint mepBuilder = |
| 485 | new DefaultMaintenanceAssociationEndPoint(); |
| 486 | mepBuilder.mepIdentifier(MepIdType.of(mep.mepId().id())); |
| 487 | ContinuityCheck cc = new DefaultContinuityCheck(); |
| 488 | cc.cciEnabled(mep.cciEnabled()); |
| 489 | mepBuilder.continuityCheck(cc); |
| 490 | mepBuilder.ccmLtmPriority( |
| 491 | PriorityType.of((short) mep.ccmLtmPriority().ordinal())); |
| 492 | mepBuilder.administrativeState(mep.administrativeState()); |
| 493 | |
| 494 | if (mep.direction() == MepDirection.UP_MEP) { |
| 495 | throw new CfmConfigException("EA1000 only supports DOWN Meps"); |
| 496 | } |
| 497 | |
| 498 | if (mep.port() == null || mep.port().toLong() < MEP_PORT_MIN |
| 499 | || mep.port().toLong() > MEP_PORT_MAX) { |
| 500 | throw new CfmConfigException("EA1000 has only ports 0 and 1. " |
| 501 | + "Rejecting Port: " + mep.port()); |
| 502 | } |
| 503 | mepBuilder.yangAutoPrefixInterface( |
| 504 | (mep.port().toLong() == 0) ? InterfaceEnum.ETH0 : InterfaceEnum.ETH1); |
| 505 | |
| 506 | return mepBuilder; |
| 507 | } |
| 508 | |
| 509 | private MepEntry buildApiMepEntryFromYangMep( |
| 510 | MaintenanceAssociationEndPoint yangMep, DeviceId deviceId, |
| 511 | MdId mdName, MaIdShort maName) throws CfmConfigException { |
| 512 | MepId mepId = MepId.valueOf((short) yangMep.mepIdentifier().uint16()); |
| 513 | MepEntry.MepEntryBuilder builder = DefaultMepEntry.builder(mepId, |
| 514 | deviceId, |
| 515 | (yangMep.yangAutoPrefixInterface() == InterfaceEnum.ETH0) ? |
| 516 | PortNumber.portNumber(0) : PortNumber.portNumber(1), |
| 517 | MepDirection.DOWN_MEP, //Always down for EA1000 |
| 518 | mdName, maName); |
| 519 | |
| 520 | if (yangMep.loopback() != null) { |
| 521 | MepLbEntryBuilder lbEntryBuilder = DefaultMepLbEntry.builder(); |
| 522 | if (yangMep.loopback().repliesReceived() != null) { |
| 523 | lbEntryBuilder = lbEntryBuilder.countLbrReceived( |
| 524 | yangMep.loopback().repliesReceived().uint32()); |
| 525 | } |
| 526 | if (yangMep.loopback().repliesTransmitted() != null) { |
| 527 | lbEntryBuilder = lbEntryBuilder.countLbrTransmitted( |
| 528 | yangMep.loopback().repliesTransmitted().uint32()); |
| 529 | } |
| 530 | builder.loopbackAttributes(lbEntryBuilder.build()); |
| 531 | } |
| 532 | |
| 533 | if (yangMep.remoteMepDatabase() != null && |
| 534 | yangMep.remoteMepDatabase().remoteMep() != null) { |
| 535 | for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 536 | .maintenancedomain.maintenanceassociation |
| 537 | .maintenanceassociationendpoint.remotemepdatabase.RemoteMep |
| 538 | rmep:yangMep.remoteMepDatabase().remoteMep()) { |
| 539 | builder = (MepEntry.MepEntryBuilder) builder.addToActiveRemoteMepList( |
| 540 | getApiRemoteMepFromYangRemoteMep(rmep)); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if (yangMep.ccmLtmPriority() != null) { |
| 545 | builder = (MepEntry.MepEntryBuilder) builder.ccmLtmPriority( |
| 546 | Priority.values()[yangMep.ccmLtmPriority().uint8()]); |
| 547 | } |
| 548 | |
| 549 | //And the the state attributes |
| 550 | builder = (MepEntry.MepEntryBuilder) builder |
| 551 | .macAddress(MacAddress.valueOf(yangMep.macAddress().toString())) |
| 552 | .administrativeState(yangMep.administrativeState()) |
| 553 | .cciEnabled(yangMep.continuityCheck().cciEnabled()); |
| 554 | |
| 555 | AugmentedMseaCfmMaintenanceAssociationEndPoint augmentedyangMep = yangMep |
| 556 | .augmentation(DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint.class); |
| 557 | |
| 558 | if (augmentedyangMep != null) { |
| 559 | if (augmentedyangMep.lastDefectSent() != null) { |
| 560 | builder = (MepEntry.MepEntryBuilder) builder |
| 561 | .activeXconCcmDefect(augmentedyangMep.lastDefectSent().bits() |
| 562 | .get(Bits.CROSS_CONNECT_CCM.bits())) |
| 563 | .activeErrorCcmDefect(augmentedyangMep.lastDefectSent().bits() |
| 564 | .get(Bits.INVALID_CCM.bits())) |
| 565 | .activeMacStatusDefect(augmentedyangMep.lastDefectSent().bits() |
| 566 | .get(Bits.REMOTE_MAC_ERROR.bits())) |
| 567 | .activeRdiCcmDefect(augmentedyangMep.lastDefectSent().bits() |
| 568 | .get(Bits.REMOTE_RDI.bits())) |
| 569 | .activeRemoteCcmDefect(augmentedyangMep.lastDefectSent().bits() |
| 570 | .get(Bits.REMOTE_INVALID_CCM.bits())); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | return builder.buildEntry(); |
| 575 | } |
| 576 | |
| 577 | private RemoteMepEntry getApiRemoteMepFromYangRemoteMep( |
| 578 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain. |
| 579 | maintenanceassociation.maintenanceassociationendpoint.remotemepdatabase. |
| 580 | RemoteMep yangRemoteMep) throws CfmConfigException { |
| 581 | |
| 582 | MepId remoteMepId = MepId.valueOf((short) yangRemoteMep.remoteMepId().uint16()); |
| 583 | RemoteMepStateTypeEnum state = RemoteMepStateTypeEnum.FAILED; |
| 584 | if (yangRemoteMep.remoteMepState() != null) { |
| 585 | state = yangRemoteMep.remoteMepState().enumeration(); |
| 586 | } |
| 587 | RemoteMepEntryBuilder rmepBuilder = DefaultRemoteMepEntry.builder( |
| 588 | remoteMepId, RemoteMepState.valueOf("RMEP_" + state.name())) |
| 589 | .rdi(yangRemoteMep.rdi()); |
| 590 | if (yangRemoteMep.macAddress() != null) { |
| 591 | rmepBuilder = rmepBuilder.macAddress( |
| 592 | MacAddress.valueOf(yangRemoteMep.macAddress().toString())); |
| 593 | } |
| 594 | if (yangRemoteMep.failedOkTime() != null) { |
| 595 | //Currently EA1000 is reporting this as 1/1000s even though yang type |
| 596 | // is time ticks 1/100s - to be fixed |
| 597 | rmepBuilder = rmepBuilder.failedOrOkTime(Duration.ofMillis( |
| 598 | yangRemoteMep.failedOkTime().uint32())); |
| 599 | } |
| 600 | if (yangRemoteMep.portStatusTlv() != null) { |
| 601 | rmepBuilder = rmepBuilder.portStatusTlvType(PortStatusTlvType.valueOf( |
| 602 | "PS_" + yangRemoteMep.portStatusTlv().enumeration().name())); |
| 603 | } |
| 604 | if (yangRemoteMep.interfaceStatusTlv() != null) { |
| 605 | rmepBuilder = rmepBuilder.interfaceStatusTlvType(InterfaceStatusTlvType.valueOf( |
| 606 | "IS_" + yangRemoteMep.interfaceStatusTlv().enumeration().name())); |
| 607 | } |
| 608 | return rmepBuilder.build(); |
| 609 | } |
| 610 | } |