blob: dc9bbb7ba4d31a994aef00d471a425b205a8abc0 [file] [log] [blame]
Sean Condonfae8e662016-12-15 10:25:13 +00001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
Sean Condonfae8e662016-12-15 10:25:13 +00003 *
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.drivers.microsemi.yang;
17
18import java.util.List;
19import java.util.concurrent.CompletableFuture;
20import java.util.concurrent.atomic.AtomicInteger;
21import java.util.regex.Pattern;
22
Sean Condon16df3b12017-06-09 15:14:01 +010023import org.onosproject.netconf.DatastoreId;
Sean Condonfae8e662016-12-15 10:25:13 +000024import org.onosproject.netconf.NetconfDeviceInfo;
25import org.onosproject.netconf.NetconfDeviceOutputEventListener;
26import org.onosproject.netconf.NetconfException;
27import org.onosproject.netconf.NetconfSession;
28import org.onosproject.netconf.TargetConfig;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32public class MockNetconfSessionEa1000 implements NetconfSession {
33 private static final Logger log = LoggerFactory
34 .getLogger(MockNetconfSessionEa1000.class);
35
36 private static final String MESSAGE_ID_STRING = "message-id";
37 private static final String EQUAL = "=";
38 private static final String RPC_OPEN = "<rpc ";
39 private static final String RPC_CLOSE = "</rpc>";
40 private static final String GET_OPEN = "<get>";
41 private static final String GET_CLOSE = "</get>";
42 private static final String NEW_LINE = "\n";
43 private static final String SUBTREE_FILTER_OPEN = "<filter type=\"subtree\">";
44 private static final String SUBTREE_FILTER_CLOSE = "</filter>";
45 private static final String WITH_DEFAULT_OPEN = "<with-defaults ";
46 private static final String WITH_DEFAULT_CLOSE = "</with-defaults>";
47 private static final String EDIT_CONFIG_OPEN = "<edit-config>";
48 private static final String EDIT_CONFIG_CLOSE = "</edit-config>";
49 private static final String TARGET_OPEN = "<target>";
50 private static final String TARGET_CLOSE = "</target>";
51 private static final String DEFAULT_OPERATION_OPEN = "<default-operation>";
52 private static final String DEFAULT_OPERATION_CLOSE = "</default-operation>";
53 private static final String CONFIG_OPEN = "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">";
54 private static final String CONFIG_CLOSE = "</config>";
55
56 private static final String ENDPATTERN = "]]>]]>";
57 private static final String XML_HEADER =
58 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
59 private static final String NETCONF_BASE_NAMESPACE =
60 "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"";
61 private static final String NETCONF_WITH_DEFAULTS_NAMESPACE =
62 "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\"";
63
64
65 private Pattern sampleXmlRegex1 =
66 Pattern.compile("(<\\?xml).*(<rpc).*(<get>).*(<filter).*"
67 + "(<system).*(<clock/>).*(</system>).*(</filter>)*.(</get>).*(</rpc).*(]]>){2}",
68 Pattern.DOTALL);
69
70 private Pattern sampleXmlRegex2 =
71 Pattern.compile("(<\\?xml).*(<rpc).*(<get>).*(<filter).*(<system-state).*(</system-state>).*"
72 + "(<system).*(</system>).*(</filter>).*(</get>).*(</rpc).*(]]>){2}",
73 Pattern.DOTALL);
74
75 private Pattern sampleXmlRegexSaFiltering =
76 Pattern.compile("(<\\?xml).*"
77 + "(<rpc).*(<get>).*"
78 + "(<filter type=\"subtree\">).*(<source-ipaddress-filtering).*"
79 + "(</filter>).*(</get>).*(</rpc>).*"
80 + "(]]>){2}", Pattern.DOTALL);
81
82 private Pattern sampleXmlRegexEditConfigSaFilt =
83 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>).*"
84 + "(<target><running/></target>).*(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">).*"
85 + "(<source-ipaddress-filtering).*(<interface-eth0>).*"
86 + "(<source-address-range>).*(<range-id>).*(</range-id>).*"
87 + "(<name>).*(</name>).*(<ipv4-address-prefix>).*(</ipv4-address-prefix>).*"
88 + "(</source-address-range>).*(</interface-eth0>)*(</source-ipaddress-filtering>).*"
89 + "(</config>).*(</edit-config>).*(</rpc>).*(]]>){2}", Pattern.DOTALL);
90
91 private Pattern sampleXmlRegexEditDeleteSaFilt =
Sean Condon16df3b12017-06-09 15:14:01 +010092 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
93 + "(<target><running/></target>)\\R?"
94 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +000095 + "(<source-ipaddress-filtering "
Sean Condon16df3b12017-06-09 15:14:01 +010096 + "xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-sa-filtering\">)\\R?"
97 + "(<interface-eth0>)\\R?"
98 + "((<source-address-range nc:operation=\"delete\">)\\R?"
99 + "(<range-id>)[0-9]*(</range-id>)\\R?"
100 + "((<name>)[a-zA-Z0-9]*(</name>))?\\R?"
101 + "((<ipv4-address-prefix>)[0-9\\\\./]*(</ipv4-address-prefix>))?\\R?"
102 + "(</source-address-range>))++\\R?"
103 + "(</interface-eth0>)\\R?"
104 + "(</source-ipaddress-filtering>)\\R?"
105 + "(</config>)\\R?"
106 + "(</edit-config>)\\R?(</rpc>).*(]]>){2}", Pattern.DOTALL);
Sean Condonfae8e662016-12-15 10:25:13 +0000107
108 private Pattern sampleXmlRegexUniEvc =
109 Pattern.compile("(<\\?xml).*(<rpc).*(<get-config>)\\R?"
110 + "(<source>)\\R?(<running/>)\\R?(</source>)\\R?"
111 + "(<filter type=\"subtree\">)\\R?"
112 + "(<mef-services "
113 + "xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\"/>)\\R?"
114 + "(</filter>)\\R?(</get-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
115
116 private Pattern sampleXmlRegexUniEvcUni =
117 Pattern.compile("(<\\?xml).*(<rpc).*(<get-config>)\\R?"
118 + "(<source>)\\R?(<running/>)\\R?(</source>)\\R?"
119 + "(<filter type=\"subtree\">)\\R?"
120 + "(<mef-services "
121 + "xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">)\\R?"
122 + "(<uni/>)\\R?"
123 + "(</mef-services>)\\R?"
124 + "(</filter>)\\R?(</get-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
125
126 private Pattern sampleXmlRegexEditConfigUni1Evc =
127 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
128 + "(<target><running/></target>)\\R?"
129 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
130 + "(<mef-services).*(<uni>)\\R?(<name>).*(</name>)\\R?"
131 + "(<evc>)\\R?(<evc-index>).*(</evc-index>)\\R?(<name>).*(</name>)\\R?"
132 + "(<evc-per-uni>)\\R?"
133 + "(<evc-per-uni-c>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100134 + "(<ce-vlan-map>)[0-9]*(</ce-vlan-map>)\\R?"
135 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
136 + "(<tag-push>)\\R?(<push-tag-type>)pushStag(</push-tag-type>)\\R?"
137 + "(<outer-tag-vlan>)[0-9]*(</outer-tag-vlan>)\\R?(</tag-push>)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000138 + "((<flow-mapping>)\\R?"
139 + "(<ce-vlan-id>)[0-9]*(</ce-vlan-id>)\\R?"
140 + "(<flow-id>)[0-9]*(</flow-id>)\\R?"
141 + "(</flow-mapping>)\\R?)*"
142 + "(</evc-per-uni-c>)\\R?"
143 + "(<evc-per-uni-n>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100144 + "(<ce-vlan-map>)[0-9\\:\\,]*(</ce-vlan-map>)\\R?"
145 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000146 + "(<tag-pop).*"
147 + "((<flow-mapping>)\\R?"
148 + "(<ce-vlan-id>)[0-9]*(</ce-vlan-id>)\\R?"
149 + "(<flow-id>)[0-9]*(</flow-id>)\\R?"
150 + "(</flow-mapping>)\\R?)*"
151 + "(</evc-per-uni-n>)\\R?"
152 + "(</evc-per-uni>)\\R?"
153 + "(</evc>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100154 + "(</uni>)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000155 + "(</mef-services>)\\R?"
156 + "(</config>)\\R?(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
157
158 private Pattern sampleXmlRegexEditConfigUni2Evc =
159 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
160 + "(<target><running/></target>)\\R?"
161 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
162 + "(<mef-services).*(<uni>)\\R?(<name>)[0-9a-zA-Z\\-\\:]*(</name>)\\R?"
163 + "(<evc>)\\R?(<evc-index>)[0-9]*(</evc-index>)\\R?(<name>)[0-9a-zA-Z\\-\\:]*(</name>)\\R?"
164 + "(<evc-per-uni>)\\R?"
165 + "(<evc-per-uni-c>)\\R?"
166 + "(<ce-vlan-map>)[0-9\\:\\,]*(</ce-vlan-map>)\\R?"
167 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
168 + "(</evc-per-uni-c>)\\R?"
169 + "(<evc-per-uni-n>)\\R?"
170 + "(<ce-vlan-map>)[0-9\\:\\,]*(</ce-vlan-map>)\\R?"
171 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
172 + "(<evc-per-uni-service-type>).*(</evc-per-uni-service-type>)\\R?"
173 + "(<tag-push>)\\R?(<push-tag-type>)pushStag(</push-tag-type>)\\R?(<outer-tag-vlan>).*"
174 + "(</outer-tag-vlan>)\\R?(</tag-push>)\\R?"
175 + "(</evc-per-uni-n>)\\R?"
176 + "(</evc-per-uni>)\\R?"
177 + "(</evc>)\\R?"
178 + "(<evc>)\\R?(<evc-index>)[0-9]*(</evc-index>)\\R?(<name>)[0-9a-zA-Z\\-\\:]*(</name>)\\R?"
179 + "(<evc-per-uni>)\\R?"
180 + "(<evc-per-uni-c>)\\R?"
181 + "(<ce-vlan-map>)[0-9\\:\\,]*(</ce-vlan-map>)\\R?"
182 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
183 + "(</evc-per-uni-c>)\\R?"
184 + "(<evc-per-uni-n>)\\R?"
185 + "(<ce-vlan-map>)[0-9\\:\\,]*(</ce-vlan-map>)\\R?"
186 + "(<ingress-bwp-group-index>)[0-9]*(</ingress-bwp-group-index>)\\R?"
187 + "(</evc-per-uni-n>)\\R?"
188 + "(</evc-per-uni>)\\R?"
189 + "(</evc>)\\R?(</uni>).*"
190 + "(</mef-services>)\\R?"
191 + "(</config>)\\R?(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
192
193 private Pattern sampleXmlRegexEditConfigUniProfiles =
194 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>).*"
195 + "(<target><running/></target>).*(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">).*"
196 + "(<mef-services).*(<profiles>).*"
Sean Condonfae8e662016-12-15 10:25:13 +0000197 + "(<bwp-group>).*(<group-index>).*(</group-index>).*"
198 + "(<bwp>).*(<cos-index>).*(</cos-index>).*(<color-mode>).*(</color-mode>).*(</bwp>).*"
Sean Condonfae8e662016-12-15 10:25:13 +0000199 + "(</bwp-group>).*"
200 + "(</profiles>).*(</mef-services>).*"
201 + "(</config>).*(</edit-config>).*(</rpc>).*(]]>){2}", Pattern.DOTALL);
202
203 private Pattern sampleXmlRegexEditConfigEvcDelete =
204 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>).*"
205 + "(<target><running/></target>).*(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">).*"
206 + "(<mef-services).*"
207 + "(<uni>).*"
208 + "(<evc nc:operation=\"delete\">).*(<evc-index>).*(</evc-index>).*(</evc>).*"
209 + "(</uni>).*"
210 + "(</mef-services>).*"
211 + "(</config>).*(</edit-config>).*(</rpc>).*(]]>){2}", Pattern.DOTALL);
212
213 private Pattern sampleXmlRegexGetConfigCeVlanMapsEvc =
214 Pattern.compile("(<\\?xml).*(<rpc).*(<get-config>)\\R?"
215 + "(<source>)\\R?(<running/>)\\R?(</source>)\\R?"
216 + "(<filter type=\"subtree\">)\\R?"
217 + "(<mef-services).*"
218 + "(<uni>)\\R?"
219 + "(<evc>)\\R?"
220 + "(<evc-index/>)\\R?"
221 + "(<evc-per-uni>)\\R?"
222 + "(<evc-per-uni-c><ce-vlan-map/><flow-mapping/><ingress-bwp-group-index/></evc-per-uni-c>)\\R?"
223 + "(<evc-per-uni-n><ce-vlan-map/><flow-mapping/><ingress-bwp-group-index/></evc-per-uni-n>)\\R?"
224 + "(</evc-per-uni>)\\R?"
225 + "(</evc>)\\R?"
226 + "(</uni>)\\R?"
227 + "(</mef-services>)\\R?"
228 + "(</filter>)\\R?"
229 + "(</get-config>)\\R?"
230 + "(</rpc>)\\R?"
231 + "(]]>){2}", Pattern.DOTALL);
232
233 //For test testRemoveEvcUniFlowEntries()
234 private Pattern sampleXmlRegexEditConfigCeVlanMapReplace =
235 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>).*"
236 + "(<target><running/></target>).*"
237 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">).*"
238 + "(<mef-services xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">).*"
239 + "(<uni>).*"
240 + "(<evc nc:operation=\"delete\">).*(<evc-index>.*</evc-index>).*(</evc>).*"
241 + "(<evc nc:operation=\"delete\">).*(<evc-index>.*</evc-index>).*(</evc>).*"
242 + "(<evc>).*(<evc-index>).*(</evc-index>).*(<evc-per-uni>).*"
243 + "(<evc-per-uni-c>).*"
244 + "(<ce-vlan-map nc:operation=\"replace\">).*(</ce-vlan-map>).*"
245 + "(<flow-mapping nc:operation=\"delete\">).*(<ce-vlan-id>).*(</ce-vlan-id>).*(</flow-mapping>).*"
246 + "(</evc-per-uni-c>).*"
247 + "(<evc-per-uni-n>).*"
248 + "(<ce-vlan-map nc:operation=\"replace\">).*(</ce-vlan-map>).*"
249 + "(<flow-mapping nc:operation=\"delete\">).*(<ce-vlan-id>).*(</ce-vlan-id>).*(</flow-mapping>).*"
250 + "(</evc-per-uni-n>).*"
251 + "(</evc-per-uni>).*(</evc>).*"
252 + "(<evc>).*(<evc-index>).*(</evc-index>).*(<evc-per-uni>).*"
253 + "(<evc-per-uni-c>).*"
254 + "(<ce-vlan-map nc:operation=\"replace\">).*(</ce-vlan-map>).*"
255 + "(<flow-mapping nc:operation=\"delete\">).*(<ce-vlan-id>).*(</ce-vlan-id>).*(</flow-mapping>).*"
256 + "(</evc-per-uni-c>).*"
257 + "(<evc-per-uni-n>).*"
258 + "(<ce-vlan-map nc:operation=\"replace\">).*(</ce-vlan-map>).*"
259 + "(<flow-mapping nc:operation=\"delete\">).*(<ce-vlan-id>).*(</ce-vlan-id>).*(</flow-mapping>).*"
260 + "(</evc-per-uni-n>).*"
261 + "(</evc-per-uni>).*(</evc>).*"
262 + "(</uni>).*(</mef-services>).*"
263 + "(</config>).*(</edit-config>).*(</rpc>).*(]]>){2}", Pattern.DOTALL);
264
265
266 //For testPerformMeterOperationDeviceIdMeterAdd()
267 private Pattern sampleXmlRegexEditConfigBwpGroup1 =
268 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
269 + "(<target>\\R?<running/>\\R?</target>)\\R?"
270 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
271 + "(<mef-services "
272 + "xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">)\\R?"
273 + "(<profiles>)\\R?"
274 + "(<bwp-group>)\\R?"
275 + "(<group-index>)[0-9]*(</group-index>)\\R?"
276 + "(<bwp>)\\R?"
277 + "(<cos-index>)[0-9]*(</cos-index>)\\R?"
278 + "(<name>).*(</name>)\\R?"
279 + "(<committed-information-rate>)[0-9]*(</committed-information-rate>)\\R?"
280 + "(<committed-burst-size>)[0-9]*(</committed-burst-size>)\\R?"
281 + "(<excess-information-rate>)[0-9]*(</excess-information-rate>)\\R?"
282 + "(<excess-burst-size>)[0-9]*(</excess-burst-size>)\\R?"
283 + "(</bwp>)\\R?"
284 + "(</bwp-group>)\\R?"
285 + "(<cos>)\\R?"
286 + "(<cos-index>)[0-9](</cos-index>)\\R?"
287 + "(<name>).*(</name>)\\R?"
288 + "(<outgoing-cos-value>)[0-9]*(</outgoing-cos-value>)\\R?"
289 + "(<color-aware>true</color-aware>)\\R?"
290 + "(<color-forward>true</color-forward>)\\R?"
291 + "(<evc-cos-type-all-8-prio-to-1-evc-color>)\\R?"
292 + "(<evc-all-8-color-to>green</evc-all-8-color-to>)\\R?"
293 + "(</evc-cos-type-all-8-prio-to-1-evc-color>)\\R?"
294 + "(</cos>)\\R?"
295 + "(</profiles>)\\R?"
296 + "(</mef-services>)\\R?"
297 + "(</config>)\\R?(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
298
299 //For testPerformMeterOperationDeviceIdMeterRemove()
300 private Pattern sampleXmlRegexEditConfigBwpGroup1Delete =
301 Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
302 + "(<target>\\R?<running/>\\R?</target>)\\R?"
303 + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
304 + "(<mef-services xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">)\\R?"
305 + "(<profiles>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100306 + "((<bwp-group nc:operation=\"delete\">)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000307 + "(<group-index>)[0-9]*(</group-index>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100308 + "(<bwp>.*</bwp>)?"
309 + "(</bwp-group>))++\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000310 + "(</profiles>)\\R?"
311 + "(</mef-services>)\\R?"
312 + "(</config>)\\R?(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
313
314 private Pattern sampleXmlRegexSetCurrentDatetime =
315 Pattern.compile("(<\\?xml).*(<rpc).*"
316 + "(<set-current-datetime xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\">)\\R?"
317 + "(<current-datetime>)"
318 + "[0-9]{4}-[0-9]{2}-[0-9]{2}(T)[0-9]{2}:[0-9]{2}:[0-9]{2}[+-][0-9]{2}:[0-9]{2}"
319 + "(</current-datetime>)\\R?"
320 + "(</set-current-datetime>)\\R?"
321 + "(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
322
323 //For testGetConfigMseaCfmEssentials
324 private Pattern sampleXmlRegexGetMseaCfmEssentials =
325 Pattern.compile("(<\\?xml).*(<rpc).*(<get>)\\R?"
326 + "(<filter type=\"subtree\">)\\R?"
327 + "(<mef-cfm).*"
328 + "(<maintenance-domain>)\\R?"
329 + "(<id/>)\\R?"
330 + "(<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>)\\R?"
331 + "(<md-level/>)\\R?"
332 + "(<maintenance-association>)\\R?"
333 + "(<id/>)\\R?"
334 + "(<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100335 + "(<ccm-interval>)[0-9]{1,3}(ms</ccm-interval>)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000336 + "(<remote-meps/>)\\R?"
337 + "(<component-list/>)\\R?"
338 + "(<maintenance-association-end-point>)\\R?"
339 + "(<mep-identifier>)[0-9]{1,4}(</mep-identifier>)\\R?"
340 + "(<interface/>)\\R?"
341 + "(<primary-vid/>)\\R?"
342 + "(<administrative-state/>)\\R?"
343 + "(<ccm-ltm-priority/>)\\R?"
344 + "(<continuity-check/>)\\R?"
345 + "(<mac-address/>)\\R?"
346 + "(<msea-soam-fm:port-status/>)\\R?"
347 + "(<msea-soam-fm:interface-status/>)\\R?"
Sean Condon16df3b12017-06-09 15:14:01 +0100348 + "(<msea-soam-fm:last-defect-sent/>)\\R?"
Sean Condonfae8e662016-12-15 10:25:13 +0000349 + "(<msea-soam-fm:rdi-transmit-status/>)\\R?"
350 + "(<loopback/>)\\R?"
351 + "(<remote-mep-database/>)\\R?"
352 + "(<linktrace/>)\\R?"
353 + "(</maintenance-association-end-point>)\\R?"
354 + "(</maintenance-association>)\\R?"
355 + "(</maintenance-domain>)\\R?"
356 + "(</mef-cfm>)\\R?"
357 + "(</filter>)\\R?"
358 + "(</get>)\\R?"
359 + "(</rpc>)\\R?"
360 + "(]]>){2}", Pattern.DOTALL);
361
362
363 private static final String SAMPLE_SYSTEM_REPLY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
364 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
365 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
366 + "<system xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\">\n"
367 + "<clock><timezone-name>Etc/UTC</timezone-name></clock>\n"
368 + "</system>\n"
369 + "</data>\n"
370 + "</rpc-reply>";
371
372 private static final String SAMPLE_SYSTEM_REPLY_INIT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
373 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">"
374 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
375 + "<system xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\">\n"
376 + "<longitude xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-system\">-8.4683990</longitude>\n"
377 + "<latitude xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-system\">51.9036140</latitude>\n"
378 + "</system>\n"
379 + "<system-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\""
380 + " xmlns:sysms=\"http://www.microsemi.com/microsemi-edge-assure/msea-system\">\n"
381 + "<platform>\n"
382 + "<os-release>4.4.0-53-generic</os-release>\n"
383 + "<sysms:device-identification>\n"
384 + "<sysms:serial-number>Eagle Simulator.</sysms:serial-number>\n"
385 + "</sysms:device-identification>\n"
386 + "</platform>\n"
387 + "</system-state>\n"
388 + "</data>"
389 + "</rpc-reply>";
390
391 private static final String SAMPLE_MSEASAFILTERING_FE_REPLY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
392 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
393 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
394 + "<source-ipaddress-filtering "
395 + "xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-sa-filtering\">\n"
396 + "<interface-eth0>\n"
397 + "<filter-admin-state>inactive</filter-admin-state>\n"
398 + "<source-address-range>\n"
399 + "<range-id>1</range-id>\n"
400 + "<ipv4-address-prefix>10.10.10.10/16</ipv4-address-prefix>\n"
401 + "<name>Filter1</name>\n"
402 + "</source-address-range>\n"
403 + "<source-address-range>\n"
404 + "<range-id>2</range-id>\n"
405 + "<ipv4-address-prefix>20.30.40.50/18</ipv4-address-prefix>\n"
406 + "<name>Flow:5e0000abaa2772</name>\n"
407 + "</source-address-range>\n"
408 + "</interface-eth0>\n"
409 + "</source-ipaddress-filtering>\n"
410 + "</data>\n"
411 + "</rpc-reply>";
412
413 private static final String SAMPLE_MSEAEVCUNI_REPLY_INIT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
414 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
415 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
416 + "<mef-services xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\"/>"
417 + "</data>\n"
418 + "</rpc-reply>";
419
420 private static final String SAMPLE_MSEAEVCUNI_FE_REPLY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
421 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
422 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
423 + "<mef-services xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">\n"
424 + "<uni>\n"
425 + "<name>Flow:7557655abfecd57865</name>\n"
426 + "<evc>\n"
427 + "<evc-index>7</evc-index\n>"
428 + "<name>evc-7</name>\n"
429 + "<evc-per-uni>\n"
430 + "<evc-per-uni-c>\n"
431 + "<ce-vlan-map>10</ce-vlan-map>\n"
432 + "<ingress-bwp-group-index>1</ingress-bwp-group-index>\n"
433 + "<tag-push>\n"
434 + "<push-tag-type>pushStag</push-tag-type>\n"
435 + "<outer-tag-vlan>3</outer-tag-vlan>\n"
436 + "</tag-push>\n"
437 + "<flow-mapping>\n"
438 + "<ce-vlan-id>10</ce-vlan-id>\n"
439 + "<flow-id>27021600672053710</flow-id>\n"
440 + "</flow-mapping>\n"
441 + "<evc-per-uni-service-type>epl</evc-per-uni-service-type>\n"
442 + "</evc-per-uni-c>\n"
443 + "<evc-per-uni-n>\n"
444 + "<ce-vlan-map>11</ce-vlan-map>\n"
445 + "<ingress-bwp-group-index>0</ingress-bwp-group-index>\n"
446 + "<flow-mapping>\n"
447 + "<ce-vlan-id>11</ce-vlan-id>\n"
448 + "<flow-id>27021600672053711</flow-id>\n"
449 + "</flow-mapping>\n"
450 + "</evc-per-uni-n>\n"
451 + "</evc-per-uni>\n"
452 + "<uni-evc-id>EA1000-Uni-from-ONOS_5</uni-evc-id>\n"
453 + "<evc-status>\n"
454 + "<operational-state>unknown</operational-state>\n"
455 + "<max-mtu-size>9600</max-mtu-size>\n"
456 + "<max-num-uni>2</max-num-uni>\n"
457 + "</evc-status>\n"
458 + "</evc>\n"
459 + "<evc>\n"
460 + "<evc-index>8</evc-index>\n"
461 + "<name>evc-8</name>\n"
462 + "<evc-per-uni>\n"
463 + "<evc-per-uni-c>\n"
464 + "<ce-vlan-map>12:14,20:22,25</ce-vlan-map>\n"
465 + "<ingress-bwp-group-index>0</ingress-bwp-group-index>\n"
466 + "<tag-pop />\n"
467 + "<evc-per-uni-service-type>epl</evc-per-uni-service-type>\n"
468 + "<flow-mapping>\n"
469 + "<ce-vlan-id>12</ce-vlan-id>\n"
470 + "<flow-id>27021600672053712</flow-id>\n"
471 + "</flow-mapping>\n"
472 + "<flow-mapping>\n"
473 + "<ce-vlan-id>13</ce-vlan-id>\n"
474 + "<flow-id>27021600672053713</flow-id>\n"
475 + "</flow-mapping>\n"
476 + "<flow-mapping>\n"
477 + "<ce-vlan-id>14</ce-vlan-id>\n"
478 + "<flow-id>27021600672053714</flow-id>\n"
479 + "</flow-mapping>\n"
480 + "<flow-mapping>\n"
481 + "<ce-vlan-id>20</ce-vlan-id>\n"
482 + "<flow-id>27021600672053720</flow-id>\n"
483 + "</flow-mapping>\n"
484 + "<flow-mapping>\n"
485 + "<ce-vlan-id>21</ce-vlan-id>\n"
486 + "<flow-id>27021600672053721</flow-id>\n"
487 + "</flow-mapping>\n"
488 + "<flow-mapping>\n"
489 + "<ce-vlan-id>22</ce-vlan-id>\n"
490 + "<flow-id>27021600672053722</flow-id>\n"
491 + "</flow-mapping>\n"
492 + "<flow-mapping>\n"
493 + "<ce-vlan-id>25</ce-vlan-id>\n"
494 + "<flow-id>27021600672053725</flow-id>\n"
495 + "</flow-mapping>\n"
496 + "</evc-per-uni-c>\n"
497 + "<evc-per-uni-n>\n"
498 + "<ce-vlan-map>13</ce-vlan-map>\n"
499 + "<ingress-bwp-group-index>0</ingress-bwp-group-index>\n"
500 + "<flow-mapping>\n"
501 + "<ce-vlan-id>13</ce-vlan-id>\n"
502 + "<flow-id>27021600672053713</flow-id>\n"
503 + "</flow-mapping>\n"
504 + "</evc-per-uni-n>\n"
505 + "</evc-per-uni>\n"
506 + "<uni-evc-id>EA1000-Uni-from-ONOS_5</uni-evc-id>\n"
507 + "<evc-status>\n"
508 + "<operational-state>unknown</operational-state>\n"
509 + "<max-mtu-size>9600</max-mtu-size>\n"
510 + "<max-num-uni>2</max-num-uni>\n"
511 + "</evc-status>\n"
512 + "</evc>\n"
513 + "</uni>\n"
514 + "<profiles>\n"
515 + "<bwp-group>\n"
516 + "<group-index>0</group-index>\n"
517 + "</bwp-group>\n"
518 + "</profiles>\n"
519 + "</mef-services>\n"
520 + "</data>\n"
521 + "</rpc-reply>";
522
523 private static final String SAMPLE_MSEAEVCUNI_CEVLANMAP_EVC_REPLY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
524 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
525 + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
526 + "<mef-services xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-uni-evc-service\">\n"
527 + "<uni>\n"
528
529 + "<evc><evc-index>1</evc-index>\n"
530 + "<evc-per-uni>\n"
531 + "<evc-per-uni-c>\n"
532 + "<ce-vlan-map>101</ce-vlan-map>\n"
533 + "<flow-mapping>\n"
534 + "<ce-vlan-id>101</ce-vlan-id>\n"
535 + "<flow-id>27021598629213101</flow-id>\n"
536 + "</flow-mapping>\n"
537 + "</evc-per-uni-c>\n"
538 + "<evc-per-uni-n>\n"
539 + "<ce-vlan-map>102</ce-vlan-map>\n"
540 + "<flow-mapping>\n"
541 + "<ce-vlan-id>102</ce-vlan-id>\n"
542 + "<flow-id>27021598629213102</flow-id>\n"
543 + "</flow-mapping>\n"
544 + "</evc-per-uni-n>\n"
545 + "</evc-per-uni>\n"
546 + "</evc>\n"
547
548 + "<evc><evc-index>7</evc-index>\n"
549 + "<evc-per-uni>\n"
550 + "<evc-per-uni-c>\n"
551 + "<ce-vlan-map>700,710,720</ce-vlan-map>\n"
552 + "<flow-mapping>\n"
553 + "<ce-vlan-id>700</ce-vlan-id>\n"
554 + "<flow-id>27021598629213700</flow-id>\n"
555 + "</flow-mapping>\n"
556 + "<flow-mapping>\n"
557 + "<ce-vlan-id>710</ce-vlan-id>\n"
558 + "<flow-id>27021598629213710</flow-id>\n"
559 + "</flow-mapping>\n"
560 + "<flow-mapping>\n"
561 + "<ce-vlan-id>720</ce-vlan-id>\n"
562 + "<flow-id>27021598629213720</flow-id>\n"
563 + "</flow-mapping>\n"
564 + "</evc-per-uni-c>\n"
565 + "<evc-per-uni-n>\n"
566 + "<ce-vlan-map>701:703</ce-vlan-map>\n"
567 + "<flow-mapping>\n"
568 + "<ce-vlan-id>701</ce-vlan-id>\n"
569 + "<flow-id>27021598629213701</flow-id>\n"
570 + "</flow-mapping>\n"
571 + "<flow-mapping>\n"
572 + "<ce-vlan-id>702</ce-vlan-id>\n"
573 + "<flow-id>27021598629213702</flow-id>\n"
574 + "</flow-mapping>\n"
575 + "<flow-mapping>\n"
576 + "<ce-vlan-id>703</ce-vlan-id>\n"
577 + "<flow-id>27021598629213703</flow-id>\n"
578 + "</flow-mapping>\n"
579 + "</evc-per-uni-n>\n"
580 + "</evc-per-uni>\n"
581 + "</evc>\n"
582
583 + "<evc><evc-index>8</evc-index>\n"
584 + "<evc-per-uni>\n"
585 + "<evc-per-uni-c>\n<ce-vlan-map>800,810,820</ce-vlan-map>\n</evc-per-uni-c>\n"
586 + "<evc-per-uni-n>\n<ce-vlan-map>801:803</ce-vlan-map>\n</evc-per-uni-n>\n"
587 + "</evc-per-uni>\n"
588 + "</evc>\n"
589
590 + "</uni>\n"
591 + "</mef-services>\n"
592 + "</data>\n"
593 + "</rpc-reply>";
594
595 private static final String SAMPLE_MSEACFM_MD_MA_MEP_REPLY =
596 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
597 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"47\">"
598 + "<data>"
599 + "<mef-cfm xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-cfm\" "
600 + "xmlns:msea-soam-fm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-fm\" "
601 + "xmlns:msea-soam-pm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-pm\">"
602 + "<maintenance-domain>"
603 + "<id>1</id>"
604 + "<name>md-1</name>"
605 + "<md-level>3</md-level>"
606 + "<maintenance-association>"
607 + "<id>1</id>"
608 + "<name>ma-1-1</name>"
609 + "<ccm-interval>10ms</ccm-interval>" //Causing problems on create of MA
610 + "<remote-meps>1</remote-meps>"
611 + "<remote-meps>2</remote-meps>"
612 + "<component-list>"
613 + "<vid>100</vid>"
614 + "<tag-type>vlan-stag</tag-type>"
615 + "</component-list>"
616 + "<maintenance-association-end-point>"
617 + "<mep-identifier>1</mep-identifier>"
618 + "<interface>eth1</interface>"
619 + "<primary-vid>100</primary-vid>"
620 + "<administrative-state>true</administrative-state>"
621 + "<ccm-ltm-priority>4</ccm-ltm-priority>"
622 + "<continuity-check>"
623 + "<cci-enabled>true</cci-enabled>"
624 + "<fng-state>report-defect</fng-state>"
625 + "<highest-priority-defect-found>remote-mac-error</highest-priority-defect-found>"
626 + "<active-defects> remote-mac-error invalid-ccm</active-defects>"
627 + "<last-error-ccm>U2FtcGxlIGxhc3QgZXJyb3IgY2NtAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
628 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
629 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
630 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAA==</last-error-ccm>"
631 + "<ccm-sequence-error-count>10</ccm-sequence-error-count>"
632 + "<sent-ccms>15</sent-ccms>"
633 + "</continuity-check>"
634 + "<mac-address>53:65:61:6e:20:43</mac-address>"
635 + "<msea-soam-fm:port-status>no-status-tlv</msea-soam-fm:port-status>"
636 + "<msea-soam-fm:interface-status>no-status-tlv</msea-soam-fm:interface-status>"
637// + "<msea-soam-fm:last-defect-sent/>" --Can't handle this at the moment
638 + "<msea-soam-fm:rdi-transmit-status>false</msea-soam-fm:rdi-transmit-status>"
639 + "<loopback>"
640 + "<replies-received>123</replies-received>"
641 + "<replies-transmitted>456</replies-transmitted>"
642 + "</loopback>"
643 + "<remote-mep-database>"
644 + "<remote-mep>"
645 + "<remote-mep-id>2</remote-mep-id>"
646 + "<remote-mep-state>ok</remote-mep-state>"
647 + "<failed-ok-time>1490692834</failed-ok-time>"
648 + "<mac-address>53:65:61:6e:20:43</mac-address>"
649 + "<rdi>true</rdi>"
650 + "<port-status-tlv>up</port-status-tlv>"
651 + "<interface-status-tlv>dormant</interface-status-tlv>"
652 + "</remote-mep>"
653 + "</remote-mep-database>"
654 + "<linktrace>"
655 + "<unexpected-replies-received>0</unexpected-replies-received>"
656 + "<msea-soam-fm:ltm-msgs-transmitted>2</msea-soam-fm:ltm-msgs-transmitted>"
657 + "<msea-soam-fm:ltm-msgs-received>2</msea-soam-fm:ltm-msgs-received>"
658 + "<msea-soam-fm:ltr-msgs-transmitted>2</msea-soam-fm:ltr-msgs-transmitted>"
659 + "<msea-soam-fm:ltr-msgs-received>2</msea-soam-fm:ltr-msgs-received>"
660 + "<linktrace-database/>"
661 + "</linktrace>"
662 + "</maintenance-association-end-point>"
663 + "<remote-meps>4</remote-meps>"
664 + "</maintenance-association>"
665 + "</maintenance-domain>"
666 + "</mef-cfm>"
667 + "</data>"
668 + "</rpc-reply>";
669
670 private static final String SAMPLE_MSEACFM_MD_MA_MEP_REPLY2 =
671 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
672 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"47\">"
673 + "<data>"
674 + "<mef-cfm xmlns=\"http://www.microsemi.com/microsemi-edge-assure/msea-cfm\" "
675 + "xmlns:msea-soam-fm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-fm\" "
676 + "xmlns:msea-soam-pm=\"http://www.microsemi.com/microsemi-edge-assure/msea-soam-pm\">"
677 + "<maintenance-domain>"
678 + "<id>1</id>"
679 + "<name>Microsemi</name>"
680 + "<md-level>2</md-level>"
681 + "<maintenance-association>"
682 + "<id>1</id>"
683 + "<name>example-ma</name>"
684 + "<remote-meps>1</remote-meps>"
685 + "<remote-meps>2</remote-meps>"
686 + "<component-list>"
687 + "<vid>100</vid>"
688 + "<tag-type>vlan-stag</tag-type>"
689 + "</component-list>"
690 + "<maintenance-association-end-point>"
691 + "<mep-identifier>4</mep-identifier>"
692 + "<interface>eth1</interface>"
693 + "<primary-vid>100</primary-vid>"
694 + "<administrative-state>true</administrative-state>"
695 + "<ccm-ltm-priority>4</ccm-ltm-priority>"
696 + "<continuity-check>"
697 + "<cci-enabled>true</cci-enabled>"
698 + "<fng-state>defect-reported</fng-state>"
699 + "<highest-priority-defect-found>remote-invalid-ccm</highest-priority-defect-found>"
700// + "<active-defects> remote-invalid-ccm</active-defects>"
701 + "<active-defects/>"
702 + "<ccm-sequence-error-count>0</ccm-sequence-error-count>"
703 + "<sent-ccms>41013</sent-ccms>"
704 + "</continuity-check>"
705 + "<mac-address>00:b0:ae:03:ff:31</mac-address>"
706 + "<msea-soam-fm:port-status>up</msea-soam-fm:port-status>"
707 + "<msea-soam-fm:interface-status>up</msea-soam-fm:interface-status>"
708 + "<msea-soam-fm:rdi-transmit-status>true</msea-soam-fm:rdi-transmit-status>"
709 + "<loopback>"
710 + "<replies-received>0</replies-received>"
711 + "<replies-transmitted>0</replies-transmitted>"
712 + "</loopback>"
713 + "<remote-mep-database>"
714 + "<remote-mep>"
715 + "<remote-mep-id>1</remote-mep-id>"
716 + "<remote-mep-state>failed</remote-mep-state>"
717 + "<failed-ok-time>26315533</failed-ok-time>"
718 + "<mac-address>00:00:00:00:00:00</mac-address>"
719 + "<rdi>false</rdi>"
720 + "<port-status-tlv>no-status-tlv</port-status-tlv>"
721 + "<interface-status-tlv>no-status-tlv</interface-status-tlv>"
722 + "</remote-mep>"
723 + "<remote-mep>"
724 + "<remote-mep-id>2</remote-mep-id>"
725 + "<remote-mep-state>failed</remote-mep-state>"
726 + "<failed-ok-time>26315541</failed-ok-time>"
727 + "<mac-address>00:00:00:00:00:00</mac-address>"
728 + "<rdi>false</rdi>"
729 + "<port-status-tlv>no-status-tlv</port-status-tlv>"
730 + "<interface-status-tlv>no-status-tlv</interface-status-tlv>"
731 + "</remote-mep>"
732 + "</remote-mep-database>"
733 + "<linktrace />"
734 + "</maintenance-association-end-point>"
735 + "<remote-meps>4</remote-meps>"
736 + "</maintenance-association>"
737 + "</maintenance-domain>"
738 + "</mef-cfm>"
739 + "</data>"
740 + "</rpc-reply>";
741
742 private static final String SAMPLE_REPLY_OK = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
743 + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"2\">"
744 + "<ok/>"
745 + "</rpc-reply>";
746
747 private NetconfDeviceInfo deviceInfo;
748
749 private final AtomicInteger messageIdInteger = new AtomicInteger(0);
750
751 public MockNetconfSessionEa1000(NetconfDeviceInfo deviceInfo) throws NetconfException {
752 this.deviceInfo = deviceInfo;
753 }
754
755 @Override
756 public CompletableFuture<String> request(String request) throws NetconfException {
757 // TODO Auto-generated method stub
758 return null;
759 }
760
761 @Override
762 public String get(String request) throws NetconfException {
763
764 return sendRequest(request);
765 }
766
767 @Override
768 public String get(String filterSchema, String withDefaultsMode) throws NetconfException {
769 StringBuilder rpc = new StringBuilder(XML_HEADER);
770 rpc.append(RPC_OPEN);
771 rpc.append(MESSAGE_ID_STRING);
772 rpc.append(EQUAL);
773 rpc.append("\"");
774 rpc.append(messageIdInteger.get());
775 rpc.append("\" ");
776 rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
777 rpc.append(GET_OPEN).append(NEW_LINE);
778 if (filterSchema != null) {
779 rpc.append(SUBTREE_FILTER_OPEN).append(NEW_LINE);
780 rpc.append(filterSchema).append(NEW_LINE);
781 rpc.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE);
782 }
783 if (withDefaultsMode != null) {
784 rpc.append(WITH_DEFAULT_OPEN).append(NETCONF_WITH_DEFAULTS_NAMESPACE).append(">");
785 rpc.append(withDefaultsMode).append(WITH_DEFAULT_CLOSE).append(NEW_LINE);
786 }
787 rpc.append(GET_CLOSE).append(NEW_LINE);
788 rpc.append(RPC_CLOSE).append(NEW_LINE);
789 rpc.append(ENDPATTERN);
790 String reply = sendRequest(rpc.toString());
791 checkReply(reply);
792 return reply;
793 }
794
795 @Override
796 public String doWrappedRpc(String request) throws NetconfException {
797 StringBuilder rpc = new StringBuilder(XML_HEADER);
798 rpc.append(RPC_OPEN);
799 rpc.append(MESSAGE_ID_STRING);
800 rpc.append(EQUAL);
801 rpc.append("\"");
802 rpc.append(messageIdInteger.get());
803 rpc.append("\" ");
804 rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
805 rpc.append(request);
806 rpc.append(RPC_CLOSE).append(NEW_LINE);
807 rpc.append(ENDPATTERN);
808 String reply = sendRequest(rpc.toString());
809 checkReply(reply);
810 return reply;
811 }
812
813 @Override
814 public String requestSync(String request) throws NetconfException {
815 if (!request.contains(ENDPATTERN)) {
816 request = request + NEW_LINE + ENDPATTERN;
817 }
818 String reply = sendRequest(request);
819 checkReply(reply);
820 return reply;
821 }
822
Sean Condonfae8e662016-12-15 10:25:13 +0000823
824 @Override
Sean Condon16df3b12017-06-09 15:14:01 +0100825 public String getConfig(DatastoreId targetConfiguration, String configurationSchema) throws NetconfException {
Sean Condonfae8e662016-12-15 10:25:13 +0000826 StringBuilder rpc = new StringBuilder(XML_HEADER);
827 rpc.append("<rpc ");
828 rpc.append(MESSAGE_ID_STRING);
829 rpc.append(EQUAL);
830 rpc.append("\"");
831 rpc.append(messageIdInteger.get());
832 rpc.append("\" ");
833 rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
834 rpc.append("<get-config>\n");
835 rpc.append("<source>\n");
836 rpc.append("<").append(targetConfiguration).append("/>");
837 rpc.append("</source>");
838 if (configurationSchema != null) {
839 rpc.append("<filter type=\"subtree\">\n");
840 rpc.append(configurationSchema).append("\n");
841 rpc.append("</filter>\n");
842 }
843 rpc.append("</get-config>\n");
844 rpc.append("</rpc>\n");
845 rpc.append(ENDPATTERN);
846 String reply = sendRequest(rpc.toString());
847 return checkReply(reply) ? reply : "ERROR " + reply;
848 }
849
850 @Override
851 public boolean editConfig(String newConfiguration) throws NetconfException {
Sean Condon16df3b12017-06-09 15:14:01 +0100852 return editConfig(DatastoreId.RUNNING, null, newConfiguration);
Sean Condonfae8e662016-12-15 10:25:13 +0000853 }
854
855 @Override
Sean Condon16df3b12017-06-09 15:14:01 +0100856 public boolean editConfig(DatastoreId targetConfiguration, String mode, String newConfiguration)
Sean Condonfae8e662016-12-15 10:25:13 +0000857 throws NetconfException {
858 newConfiguration = newConfiguration.trim();
859 StringBuilder rpc = new StringBuilder(XML_HEADER);
860 rpc.append(RPC_OPEN);
861 rpc.append(MESSAGE_ID_STRING);
862 rpc.append(EQUAL);
863 rpc.append("\"");
864 rpc.append(messageIdInteger.get());
865 rpc.append("\" ");
866 rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
867 rpc.append(EDIT_CONFIG_OPEN).append("\n");
868 rpc.append(TARGET_OPEN);
869 rpc.append("<").append(targetConfiguration).append("/>");
870 rpc.append(TARGET_CLOSE).append("\n");
871 if (mode != null) {
872 rpc.append(DEFAULT_OPERATION_OPEN);
873 rpc.append(mode);
874 rpc.append(DEFAULT_OPERATION_CLOSE).append("\n");
875 }
876 rpc.append(CONFIG_OPEN).append("\n");
877 rpc.append(newConfiguration);
878 rpc.append(CONFIG_CLOSE).append("\n");
879 rpc.append(EDIT_CONFIG_CLOSE).append("\n");
880 rpc.append(RPC_CLOSE);
881 rpc.append(ENDPATTERN);
882 log.debug(rpc.toString());
883 String reply = sendRequest(rpc.toString());
884 return checkReply(reply);
885 }
886
887 @Override
888 public boolean copyConfig(String targetConfiguration, String newConfiguration) throws NetconfException {
889 return copyConfig(TargetConfig.valueOf(targetConfiguration), newConfiguration);
890 }
891
892 @Override
Sean Condonfae8e662016-12-15 10:25:13 +0000893 public void startSubscription() throws NetconfException {
894 // TODO Auto-generated method stub
895
896 }
897
898 @Override
899 public void startSubscription(String filterSchema) throws NetconfException {
900 // TODO Auto-generated method stub
901
902 }
903
904 @Override
905 public void endSubscription() throws NetconfException {
906 // TODO Auto-generated method stub
907
908 }
909
910 @Override
Sean Condonfae8e662016-12-15 10:25:13 +0000911 public boolean lock() throws NetconfException {
912 // TODO Auto-generated method stub
913 return false;
914 }
915
916 @Override
917 public boolean unlock() throws NetconfException {
918 // TODO Auto-generated method stub
919 return false;
920 }
921
922 @Override
923 public boolean close() throws NetconfException {
924 // TODO Auto-generated method stub
925 return false;
926 }
927
928 @Override
929 public String getSessionId() {
930 return "mockSessionId";
931 }
932
933 @Override
934 public String getServerCapabilities() {
935 // TODO Auto-generated method stub
936 return null;
937 }
938
939 @Override
940 public void setDeviceCapabilities(List<String> capabilities) {
941 // TODO Auto-generated method stub
942
943 }
944
945 @Override
946 public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
947 // TODO Auto-generated method stub
948
949 }
950
951 @Override
952 public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
953 // TODO Auto-generated method stub
954
955 }
956
957 private boolean checkReply(String reply) throws NetconfException {
958 if (reply != null) {
959 if (!reply.contains("<rpc-error>")) {
960 log.debug("Device {} sent reply {}", deviceInfo, reply);
961 return true;
962 } else if (reply.contains("<ok/>")
963 || (reply.contains("<rpc-error>")
964 && reply.contains("warning"))) {
965 log.debug("Device {} sent reply {}", deviceInfo, reply);
966 return true;
967 }
968 }
969 log.warn("Device {} has error in reply {}", deviceInfo, reply);
970 return false;
971 }
972
973 private String sendRequest(String request) throws NetconfException {
974 log.info("Mocking NETCONF Session send request: \n" + request);
975
976 if (sampleXmlRegex1.matcher(request).matches()) {
977 return SAMPLE_SYSTEM_REPLY;
978
979 } else if (sampleXmlRegex2.matcher(request).matches()) {
980 return SAMPLE_SYSTEM_REPLY_INIT;
981
982 } else if (sampleXmlRegexSaFiltering.matcher(request).matches()) {
983 return SAMPLE_MSEASAFILTERING_FE_REPLY;
984
985 } else if (sampleXmlRegexEditConfigSaFilt.matcher(request).matches()) {
986 return SAMPLE_REPLY_OK;
987
988 } else if (sampleXmlRegexEditDeleteSaFilt.matcher(request).matches()) {
989 return SAMPLE_REPLY_OK;
990
991 } else if (sampleXmlRegexUniEvc.matcher(request).matches()) {
992 return SAMPLE_MSEAEVCUNI_REPLY_INIT;
993
994 } else if (sampleXmlRegexUniEvcUni.matcher(request).matches()) {
995 return SAMPLE_MSEAEVCUNI_FE_REPLY;
996
997 } else if (sampleXmlRegexEditConfigUni1Evc.matcher(request).matches()) {
998 return SAMPLE_REPLY_OK;
999
1000 } else if (sampleXmlRegexEditConfigUni2Evc.matcher(request).matches()) {
1001 return SAMPLE_REPLY_OK;
1002
1003 } else if (sampleXmlRegexEditConfigUniProfiles.matcher(request).matches()) {
1004 return SAMPLE_REPLY_OK;
1005
1006 } else if (sampleXmlRegexEditConfigEvcDelete.matcher(request).matches()) {
1007 return SAMPLE_REPLY_OK;
1008
1009 } else if (sampleXmlRegexGetConfigCeVlanMapsEvc.matcher(request).matches()) {
1010 return SAMPLE_MSEAEVCUNI_CEVLANMAP_EVC_REPLY;
1011
1012 } else if (sampleXmlRegexEditConfigCeVlanMapReplace.matcher(request).matches()) {
1013 return SAMPLE_REPLY_OK;
1014
1015 } else if (sampleXmlRegexEditConfigBwpGroup1.matcher(request).matches()) {
1016 return SAMPLE_REPLY_OK;
1017
1018 } else if (sampleXmlRegexEditConfigBwpGroup1Delete.matcher(request).matches()) {
1019 return SAMPLE_REPLY_OK;
1020
1021 } else if (sampleXmlRegexSetCurrentDatetime.matcher(request).matches()) {
1022 return SAMPLE_REPLY_OK;
1023
1024 } else if (sampleXmlRegexGetMseaCfmEssentials.matcher(request).matches()) {
1025 return SAMPLE_MSEACFM_MD_MA_MEP_REPLY2;
1026
1027 } else {
1028 throw new NetconfException("MocknetconfSession. No sendRequest() case for query: " +
1029 request);
1030 }
1031 }
1032}