Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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.yang.impl; |
| 17 | |
| 18 | import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML; |
| 19 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_REPLY; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
| 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
| 26 | import org.apache.felix.scr.annotations.Service; |
| 27 | import org.onosproject.drivers.microsemi.yang.MseaCfmNetconfService; |
| 28 | import org.onosproject.netconf.NetconfException; |
| 29 | import org.onosproject.netconf.NetconfSession; |
| 30 | import org.onosproject.netconf.TargetConfig; |
| 31 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.MseaCfm; |
| 32 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.MseaCfmOpParam; |
| 33 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.MseaCfmService; |
| 34 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.MseaCfmEventListener; |
| 35 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.abortloopback.AbortLoopbackInput; |
| 36 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.transmitlinktrace.TransmitLinktraceInput; |
| 37 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.transmitlinktrace.TransmitLinktraceOutput; |
| 38 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.transmitloopback.TransmitLoopbackInput; |
| 39 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.soam.fm.rev20160229.MseaSoamFmService; |
| 40 | import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.soam.pm.rev20160229.MseaSoamPmService; |
| 41 | |
| 42 | /** |
| 43 | * Implementation of the MseaCfmServiceNetconf YANG model service. |
| 44 | */ |
| 45 | @Component(immediate = true, inherit = true) |
| 46 | @Service |
| 47 | public class MseaCfmManager extends AbstractYangServiceImpl |
| 48 | implements MseaCfmNetconfService { |
| 49 | |
| 50 | public static final String MSEA_CFM = "org.onosproject.drivers.microsemi.yang.mseacfmservice"; |
| 51 | |
| 52 | @Activate |
| 53 | public void activate() { |
| 54 | appId = coreService.registerApplication(MSEA_CFM); |
| 55 | ych = ymsService.getYangCodecHandler(); |
| 56 | ych.addDeviceSchema(MseaCfmService.class); |
| 57 | ych.addDeviceSchema(MseaSoamFmService.class); |
| 58 | ych.addDeviceSchema(MseaSoamPmService.class); |
| 59 | log.info("MseaCfmService Started"); |
| 60 | } |
| 61 | |
| 62 | @Deactivate |
| 63 | public void deactivate() { |
| 64 | super.deactivate(); |
| 65 | ymsService.unRegisterService(this, MseaCfmService.class); |
| 66 | ymsService.unRegisterService(this, MseaSoamFmService.class); |
| 67 | ymsService.unRegisterService(this, MseaSoamPmService.class); |
| 68 | ych = null; |
| 69 | log.info("MseaCfmService Stopped"); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public MseaCfm getMepEssentials(String mdName, String maName, int mepId, |
| 74 | NetconfSession session) throws NetconfException { |
| 75 | if (session == null) { |
| 76 | throw new NetconfException("Session is null when calling getMepEssentials()"); |
| 77 | } |
| 78 | |
| 79 | String xmlQueryStr = buildMepQueryString(mdName, maName, mepId); |
| 80 | log.debug("Sending <get> for " + |
| 81 | " query on NETCONF session " + session.getSessionId() + |
| 82 | ":\n" + xmlQueryStr); |
| 83 | |
| 84 | String xmlResult = session.get(xmlQueryStr, null); |
| 85 | //FIXME Line is removed because YCH decode does not know how to handle it |
| 86 | xmlResult = xmlResult.replaceAll("(<ccm-interval>)(3.3ms|10ms|100ms|1s)(</ccm-interval>)", ""); |
| 87 | xmlResult = xmlResult.replaceAll("(<active-defects/>)", ""); |
| 88 | |
| 89 | List<Object> objectList = ych.decode(xmlResult, XML, QUERY_REPLY); |
| 90 | if (objectList != null && objectList.size() > 0) { |
| 91 | Object systemObject = objectList.get(0); |
| 92 | return (MseaCfm) systemObject; |
| 93 | } else { |
| 94 | throw new NetconfException("Failure of YCH decode - could not parse as MseaCfm: " + xmlResult); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public MseaCfm getSoamDm(String mdName, String maName, int mepId, |
| 100 | int dmId, NetconfSession session) throws NetconfException { |
| 101 | String xmlQueryStr = buildDmQueryString(mdName, maName, mepId, dmId); |
| 102 | log.debug("Sending <get> for " + |
| 103 | " query on NETCONF session " + session.getSessionId() + |
| 104 | ":\n" + xmlQueryStr); |
| 105 | |
| 106 | String xmlResult = session.get(xmlQueryStr, null); |
| 107 | |
| 108 | List<Object> objectList = ych.decode(xmlResult, XML, QUERY_REPLY); |
| 109 | if (objectList != null && objectList.size() > 0) { |
| 110 | Object systemObject = objectList.get(0); |
| 111 | return (MseaCfm) systemObject; |
| 112 | } else { |
| 113 | throw new NetconfException("Failure of YCH decode - could not parse as MseaCfm: " + xmlResult); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void setMseaCfm(MseaCfmOpParam mseaCfm, NetconfSession session, TargetConfig targetDs) |
| 119 | throws NetconfException { |
| 120 | setNetconfObject(mseaCfm, session, targetDs); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Call RPCs on the device through NETCONF. |
| 125 | */ |
| 126 | @Override |
| 127 | public void transmitLoopback(TransmitLoopbackInput inputVar, NetconfSession session) throws NetconfException { |
| 128 | throw new UnsupportedOperationException("Not yet implemented"); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public void abortLoopback(AbortLoopbackInput inputVar, NetconfSession session) throws NetconfException { |
| 133 | throw new UnsupportedOperationException("Not yet implemented"); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public TransmitLinktraceOutput transmitLinktrace(TransmitLinktraceInput inputVar, NetconfSession session) |
| 138 | throws NetconfException { |
| 139 | throw new UnsupportedOperationException("Not yet implemented"); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void addListener(MseaCfmEventListener listener) { |
| 144 | throw new UnsupportedOperationException("Not yet implemented"); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void removeListener(MseaCfmEventListener listener) { |
| 149 | throw new UnsupportedOperationException("Not yet implemented"); |
| 150 | } |
| 151 | |
| 152 | private String buildMepQueryString(String mdName, String maName, int mepId) { |
| 153 | StringBuilder rpc = new StringBuilder(); |
| 154 | |
| 155 | rpc.append("<mef-cfm xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-cfm\" "); |
| 156 | rpc.append(" xmlns:msea-soam-fm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-fm\" "); |
| 157 | rpc.append("xmlns:msea-soam-pm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-pm\">\n"); |
| 158 | rpc.append("<maintenance-domain>\n"); |
| 159 | rpc.append("<id/>\n"); |
| 160 | rpc.append("<name>" + mdName + "</name>\n"); |
| 161 | rpc.append("<md-level/>\n"); |
| 162 | rpc.append("<maintenance-association>\n"); |
| 163 | rpc.append("<id/>\n"); |
| 164 | rpc.append("<name>" + maName + "</name>\n"); |
| 165 | // rpc.append("<ccm-interval>10ms</ccm-interval>\n"); //Have to omit for the moment - YMS problem |
| 166 | rpc.append("<remote-meps/>\n"); |
| 167 | rpc.append("<component-list/>\n"); |
| 168 | rpc.append("<maintenance-association-end-point>\n"); |
| 169 | rpc.append("<mep-identifier>" + mepId + "</mep-identifier>\n"); |
| 170 | rpc.append("<interface/>\n"); |
| 171 | rpc.append("<primary-vid/>\n"); |
| 172 | rpc.append("<administrative-state/>\n"); |
| 173 | rpc.append("<ccm-ltm-priority/>\n"); |
| 174 | rpc.append("<continuity-check/>\n"); |
| 175 | rpc.append("<mac-address/>\n"); |
| 176 | rpc.append("<msea-soam-fm:port-status/>\n"); |
| 177 | rpc.append("<msea-soam-fm:interface-status/>\n"); |
| 178 | // rpc.append("<msea-soam-fm:last-defect-sent/>\n");//Have to omit for the moment - YMS problem |
| 179 | rpc.append("<msea-soam-fm:rdi-transmit-status/>\n"); |
| 180 | rpc.append("<loopback/>\n"); |
| 181 | rpc.append("<remote-mep-database/>\n"); |
| 182 | rpc.append("<linktrace/>\n"); |
| 183 | rpc.append("</maintenance-association-end-point>\n"); |
| 184 | rpc.append("</maintenance-association>\n"); |
| 185 | rpc.append("</maintenance-domain>\n"); |
| 186 | rpc.append("</mef-cfm>"); |
| 187 | |
| 188 | return rpc.toString(); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | private String buildDmQueryString(String mdName, String maName, int mepId, int dmId) { |
| 193 | StringBuilder rpc = new StringBuilder(); |
| 194 | |
| 195 | rpc.append("<mef-cfm xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-cfm\" "); |
| 196 | rpc.append(" xmlns:msea-soam-fm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-fm\" "); |
| 197 | rpc.append("xmlns:msea-soam-pm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-pm\">\n"); |
| 198 | rpc.append("<maintenance-domain>\n"); |
| 199 | rpc.append("<id/>\n"); |
| 200 | rpc.append("<name>" + mdName + "</name>\n"); |
| 201 | rpc.append("<md-level/>\n"); |
| 202 | rpc.append("<maintenance-association>\n"); |
| 203 | rpc.append("<id/>\n"); |
| 204 | rpc.append("<name>" + maName + "</name>\n"); |
| 205 | // rpc.append("<ccm-interval>10ms</ccm-interval>\n"); //Have to omit for the moment - YMS problem |
| 206 | rpc.append("<maintenance-association-end-point>\n"); |
| 207 | rpc.append("<mep-identifier>" + mepId + "</mep-identifier>\n"); |
| 208 | rpc.append("<msea-soam-pm:delay-measurements>"); |
| 209 | rpc.append("<msea-soam-pm:delay-measurement>"); |
| 210 | rpc.append("<msea-soam-pm:dm-id>" + dmId + "</msea-soam-pm:dm-id>"); |
| 211 | rpc.append("</msea-soam-pm:delay-measurement>"); |
| 212 | rpc.append("</msea-soam-pm:delay-measurements>"); |
| 213 | rpc.append("</maintenance-association-end-point>\n"); |
| 214 | rpc.append("</maintenance-association>\n"); |
| 215 | rpc.append("</maintenance-domain>\n"); |
| 216 | rpc.append("</mef-cfm>"); |
| 217 | |
| 218 | return rpc.toString(); |
| 219 | } |
| 220 | |
| 221 | } |