-
Notifications
You must be signed in to change notification settings - Fork 0
/
FujitsuFlowRuleProgrammable.java
701 lines (631 loc) · 29 KB
/
FujitsuFlowRuleProgrammable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/*
* Copyright 2022-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This work was partially supported by EC H2020 project B5G-OPEN(101016663).
*/
package org.onosproject.drivers.odtn;
import com.google.common.collect.ImmutableList;
import org.apache.commons.configuration.XMLConfiguration;
import org.onlab.util.Frequency;
import org.onlab.util.Spectrum;
import org.onosproject.drivers.odtn.impl.DeviceConnectionCache;
import org.onosproject.drivers.odtn.impl.FlowRuleParser;
import org.onosproject.drivers.odtn.openconfig.TerminalDeviceFlowRule;
import org.onosproject.drivers.utilities.XmlConfigParser;
import org.onosproject.net.*;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.flow.*;
import org.onosproject.netconf.DatastoreId;
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of FlowRuleProgrammable interface for
* OpenConfig terminal devices.
*/
public class FujitsuFlowRuleProgrammable
extends AbstractHandlerBehaviour implements FlowRuleProgrammable {
private static final Logger log =
LoggerFactory.getLogger(FujitsuFlowRuleProgrammable.class);
private static final String RPC_TAG_NETCONF_BASE =
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">";
private static final String RPC_CLOSE_TAG = "</rpc>";
private static final String PREFIX_PORT = "port-";
private static final String PREFIX_TRANSCEIVER = "transceiver-";
private static final String DEFAULT_TARGET_POWER = "0.0";;
private static final String OPERATION_ENABLE = "ENABLED";
private static final String OC_TYPE_PROT_OTN = "oc-opt-types:PROT_OTN";
private static final String OC_TYPE_PROT_ETH = "oc-opt-types:PROT_ETHERNET";
private static final String OC_TYPE_PROT_ODUCN = "oc-opt-types:PROT_ODUCN";
private static final String OC_TYPE_TRIB_RATE_100G = "oc-opt-types:TRIB_RATE_100G";
private static final String OC_TYPE_PROT_100GE = "oc-opt-types:PROT_100GE";
private static final String OC_TYPE_PROT_ODU4 = "oc-opt-types:PROT_ODU4";
private static final String OPTICAL_CHANNEL = "OPTICAL_CHANNEL";
private static final String LOGICAL_CHANNEL = "LOGICAL_CHANNEL";
private static final String FALSE = "false";
/**
* Apply the flow entries specified in the collection rules.
*
* @param rules A collection of Flow Rules to be applied
* @return The collection of added Flow Entries
*/
@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
NetconfSession session = getNetconfSession();
if (session == null) {
openConfigError("null session");
return ImmutableList.of();
}
log.info("dentro apply flow rules");
// Apply the rules on the device
Collection<FlowRule> added = rules.stream()
.map(r -> new TerminalDeviceFlowRule(r, getLinePorts()))
.filter(xc -> applyFlowRule(session, xc))
.collect(Collectors.toList());
for (FlowRule flowRule : added) {
log.info("OpenConfig added flowrule {}", flowRule);
getConnectionCache().add(did(), ((TerminalDeviceFlowRule) flowRule).connectionName(), flowRule);
}
//Print out number of rules sent to the device (without receiving errors)
openConfigLog("applyFlowRules added {}", added.size());
return added;
}
/**
* Get the flow entries that are present on the device.
*
* @return A collection of Flow Entries
*/
@Override
public Collection<FlowEntry> getFlowEntries() {
log.debug("getFlowEntries device {} cache size {}", did(), getConnectionCache().size(did()));
DeviceConnectionCache cache = getConnectionCache();
if (cache.get(did()) == null) {
return ImmutableList.of();
}
List<FlowEntry> entries = new ArrayList<>();
for (FlowRule r : cache.get(did())) {
entries.add(
new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
}
//Print out number of rules actually found on the device that are also included in the cache
openConfigLog("getFlowEntries fetched connections {}", entries.size());
return entries;
}
/**
* Remove the specified flow rules.
*
* @param rules A collection of Flow Rules to be removed
* @return The collection of removed Flow Entries
*/
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
NetconfSession session = getNetconfSession();
if (session == null) {
openConfigError("null session");
return ImmutableList.of();
}
List<FlowRule> removed = new ArrayList<>();
for (FlowRule r : rules) {
try {
TerminalDeviceFlowRule termFlowRule = new TerminalDeviceFlowRule(r, getLinePorts());
removeFlowRule(session, termFlowRule);
getConnectionCache().remove(did(), termFlowRule.connectionName());
removed.add(r);
} catch (Exception e) {
openConfigError("Error {}", e);
continue;
}
}
//Print out number of removed rules from the device (without receiving errors)
openConfigLog("removeFlowRules removed {}", removed.size());
return removed;
}
private DeviceConnectionCache getConnectionCache() {
return DeviceConnectionCache.init();
}
// Context so XPath expressions are aware of XML namespaces
private static final NamespaceContext NS_CONTEXT = new NamespaceContext() {
@Override
public String getNamespaceURI(String prefix) {
if (prefix.equals("oc-platform-types")) {
return "http://openconfig.net/yang/platform-types";
}
if (prefix.equals("oc-opt-term")) {
return "http://openconfig.net/yang/terminal-device";
}
return null;
}
@Override
public Iterator getPrefixes(String val) {
return null;
}
@Override
public String getPrefix(String uri) {
return null;
}
};
/**
* Helper method to get the device id.
*/
private DeviceId did() {
return data().deviceId();
}
/**
* Helper method to log from this class adding DeviceId.
*/
private void openConfigLog(String format, Object... arguments) {
log.info("OPENCONFIG {}: " + format, did(), arguments);
}
/**
* Helper method to log an error from this class adding DeviceId.
*/
private void openConfigError(String format, Object... arguments) {
log.error("OPENCONFIG {}: " + format, did(), arguments);
}
/**
* Helper method to get the Netconf Session.
*/
private NetconfSession getNetconfSession() {
NetconfController controller =
checkNotNull(handler().get(NetconfController.class));
return controller.getNetconfDevice(did()).getSession();
}
/**
* Construct a String with a Netconf filtered get RPC Message.
*
* @param filter A valid XML tree with the filter to apply in the get
* @return a String containing the RPC XML Document
*/
private String filteredGetBuilder(String filter) {
StringBuilder rpc = new StringBuilder(RPC_TAG_NETCONF_BASE);
rpc.append("<get>");
rpc.append("<filter type='subtree'>");
rpc.append(filter);
rpc.append("</filter>");
rpc.append("</get>");
rpc.append(RPC_CLOSE_TAG);
return rpc.toString();
}
/**
* Get the index of the logical channel with the corresponding optical-channel.
*
* @param session
* @param otsiPort
* @return
*/
private Long getLogicalChannelIndex (NetconfSession session, String otsiPort)
throws NetconfException {
try {
String rpcReply = session.rpc(getLogicalChannelRequest(otsiPort)).get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
log.debug("REPLY {}", rpcReply);
String channel = xconf.getString("data.terminal-device.logical-channels.channel." +
"logical-channel-assignments.assignment.state.index");
if (channel == null) {
return -1L;
}
long index = Long.parseLong(channel);
log.debug("OpticalChannel {} has index {}", otsiPort, index);
return index;
} catch (Exception e) {
throw new NetconfException("error getting the logical channels");
}
}
private void createLineLogicalChannel(NetconfSession session, String otsiPort)
throws NetconfException {
StringBuilder sb = new StringBuilder();
sb.append("<terminal-device xmlns=\"http://openconfig.net/yang/terminal-device\">");
sb.append("<logical-channels>");
sb.append("<channel>");
sb.append("<index>" + getIndex(otsiPort) +"</index>");
sb.append("<config>");
sb.append("<index>" + getIndex(otsiPort) +"</index>");
sb.append("<admin-state>" + OPERATION_ENABLE + "</admin-state>");
sb.append("<trib-protocol xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">" + OC_TYPE_PROT_ODUCN + "</trib-protocol>");
sb.append("<logical-channel-type xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+ OC_TYPE_PROT_OTN + "</logical-channel-type>");
sb.append("<test-signal>"+FALSE+"</test-signal>");
sb.append("</config>");
sb.append("<otn>");
sb.append("<config>");
sb.append("<tti-msg-transmit>hello</tti-msg-transmit>");
sb.append("<tti-msg-expected>hello</tti-msg-expected>");
sb.append("</config>");
sb.append("</otn>");
sb.append("<logical-channel-assignments>");
sb.append("<assignment>");
sb.append("<index>" + getIndex(otsiPort) +"</index>");
sb.append("<config>");
sb.append("<index>" + getIndex(otsiPort) +"</index>");
sb.append("<assignment-type>"+ OPTICAL_CHANNEL+"</assignment-type>");
sb.append("<optical-channel>"+ otsiPort +"</optical-channel>");
sb.append("</config>");
sb.append("</assignment>");
sb.append("</logical-channel-assignments>");
sb.append("</channel>");
sb.append("</logical-channels>");
sb.append("</terminal-device>");
boolean ok =
session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
session.commit();
if (!ok) {
throw new NetconfException("error writing the logical channel");
}
}
/**
* Construct the filter for a get request to retrieve all Logical Channels
*
* This method is used to query the device so we can find the
* list of current logical channel.
*
* It is used to discover the highest index curerntly configured.
*
* @return The filt content to send to the device.
*/
private String getLogicalChannelRequest(String otsiPort) {
StringBuilder filt = new StringBuilder();
filt.append("<terminal-device xmlns='http://openconfig.net/yang/terminal-device'>");
filt.append("<logical-channels>");
filt.append("<channel>");
filt.append("<logical-channel-assignments>");
filt.append("<assignment>");
filt.append("<state>");
filt.append("<optical-channel>" + otsiPort + "</optical-channel>");
filt.append("</state>");
filt.append("</assignment>");
filt.append("</logical-channel-assignments>");
filt.append("</channel>");
filt.append("</logical-channels>");
filt.append("</terminal-device>");
return filteredGetBuilder(filt.toString());
}
private void deleteLogicalChannel(NetconfSession session, Long index)
throws NetconfException {
StringBuilder sb = new StringBuilder();
sb.append("<terminal-device xmlns='http://openconfig.net/yang/terminal-device'>");
sb.append("<logical-channels>");
sb.append("<channel nc:operation=\"delete\">");
sb.append("<index>" + index + "</index>");
sb.append("</channel>");
sb.append("</logical-channels>");
sb.append("</terminal-device>");
log.info(sb.toString());
boolean ok =
session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
session.commit();
if (!ok) {
throw new NetconfException("error writing the logical channel");
}
}
private void setOpticalChannelFrequency(NetconfSession session, String optChannel, Frequency freq)
throws NetconfException {
StringBuilder sb = new StringBuilder();
sb.append("<components xmlns='http://openconfig.net/yang/platform'>");
sb.append("<component>");
sb.append("<name>" + optChannel + "</name>");
sb.append("<config>");
sb.append("<name>" + optChannel + "</name>");
sb.append("</config>");
sb.append("<optical-channel xmlns='http://openconfig.net/yang/terminal-device'>");
sb.append("<config>");
sb.append("<frequency>" + (long) freq.asMHz() + "</frequency>");
sb.append("<target-output-power>" + DEFAULT_TARGET_POWER + "</target-output-power>");
sb.append("</config>");
sb.append("</optical-channel>");
sb.append("</component>");
sb.append("</components>");
boolean ok =
session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
session.commit();
if (!ok) {
throw new NetconfException("error writing channel frequency");
}
}
private void setLogicalChannelAssignment(NetconfSession session, String operation, String client,
Long index)
throws NetconfException {
StringBuilder sb = new StringBuilder();
sb.append("<terminal-device xmlns=\"http://openconfig.net/yang/terminal-device\">");
sb.append("<logical-channels>");
sb.append("<channel>");
sb.append("<index>"+String.valueOf(index).concat(client.split("C")[1])+"</index>");
sb.append("<config>");
sb.append("<index>"+String.valueOf(index).concat(client.split("C")[1])+"</index>");
sb.append("<admin-state>"+ operation +"</admin-state>");
sb.append("<rate-class xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_TRIB_RATE_100G+"</rate-class>");
sb.append("<trib-protocol xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_PROT_ODU4+"</trib-protocol>");
sb.append("<logical-channel-type xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_PROT_OTN+"</logical-channel-type>");
sb.append("</config>");
sb.append("<logical-channel-assignments>");
sb.append("<assignment>");
sb.append("<index>"+index+"</index>");
sb.append("<config>");
sb.append("<index>"+index+"</index>");
sb.append("<assignment-type>" + LOGICAL_CHANNEL + "</assignment-type>");
sb.append("<logical-channel>"+index+"</logical-channel>");
sb.append("</config>");
sb.append("</assignment>");
sb.append("</logical-channel-assignments>");
sb.append("</channel>");
sb.append("</logical-channels>");
sb.append("<logical-channels>");
sb.append("<channel>");
sb.append("<index>"+String.valueOf(index).concat("0").concat(client.split("C")[1])+"</index>");
sb.append("<config>");
sb.append("<index>"+String.valueOf(index).concat("0").concat(client.split("C")[1])+"</index>");
sb.append("<admin-state>"+ operation +"</admin-state>");
sb.append("<rate-class xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_TRIB_RATE_100G+"</rate-class>");
sb.append("<trib-protocol xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_PROT_100GE+"</trib-protocol>");
sb.append("<logical-channel-type xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">"+OC_TYPE_PROT_ETH+"</logical-channel-type>");
sb.append("<loopback-mode>NONE</loopback-mode>");
sb.append("<test-signal>"+FALSE+"</test-signal>");
sb.append("</config>");
sb.append("<ingress>");
sb.append("<config>");
sb.append("<transceiver>"+client.replace(PREFIX_PORT,PREFIX_TRANSCEIVER)+"</transceiver>");
sb.append("</config>");
sb.append("</ingress>");
sb.append("<logical-channel-assignments>");
sb.append("<assignment>");
sb.append("<index>"+index+"</index>");
sb.append("<config>");
sb.append("<index>"+index+"</index>");
sb.append("<assignment-type>"+LOGICAL_CHANNEL+"</assignment-type>");
sb.append("<logical-channel>"+String.valueOf(index).concat(client.split("C")[1])+"</logical-channel>");
sb.append("</config>");
sb.append("</assignment>");
sb.append("</logical-channel-assignments>");
sb.append("</channel>");
sb.append("</logical-channels>");
sb.append("</terminal-device>");
log.info(sb.toString());
boolean ok =
session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
session.commit();
if (!ok) {
throw new NetconfException("error writing logical channel assignment");
}
}
private void deleteLogicalChannelAssignment(NetconfSession session, String client, Long index)
throws NetconfException {
StringBuilder sb = new StringBuilder();
sb.append("<terminal-device xmlns=\"http://openconfig.net/yang/terminal-device\">");
sb.append("<logical-channels>");
sb.append("<channel nc:operation=\"delete\">");
sb.append("<index>"+String.valueOf(index).concat(client.split("C")[1])+"</index>");
sb.append("</channel>");
sb.append("<channel nc:operation=\"delete\">");
sb.append("<index>"+String.valueOf(index).concat("0").concat(client.split("C")[1])+"</index>");
sb.append("</channel>");
sb.append("</logical-channels>");
sb.append("</terminal-device>");
log.info(sb.toString());
boolean ok =
session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
session.commit();
if (!ok) {
throw new NetconfException("error writing logical channel assignment");
}
}
/**
* Apply a single flowrule to the device.
*
* --- Directionality details:
* Driver supports ADD (INGRESS) and DROP (EGRESS) rules generated by OpticalCircuit/OpticalConnectivity intents
* the format of the rules are checked in class TerminalDeviceFlowRule
*
* However, the physical transponder is always bidirectional as specified in OpenConfig YANG models
* therefore ADD and DROP rules are mapped in the same xml that ENABLE (and tune) a transponder port.
*
* If the intent is generated as bidirectional both ADD and DROP flowrules are generated for each device, thus
* the same xml is sent twice to the device.
*
* @param session The Netconf session.
* @param rule Flow Rules to be applied.
* @return true if no Netconf errors are received from the device when xml is sent
* @throws NetconfException if exchange goes wrong
*/
protected boolean applyFlowRule(NetconfSession session, TerminalDeviceFlowRule rule) {
//Configuration of LINE side, used for OpticalConnectivity intents
//--- configure central frequency
//--- enable the line port
if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS ||
rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
FlowRuleParser frp = new FlowRuleParser(rule);
PortNumber linePort = frp.getPortNumber();
Frequency centralFrequency = frp.getCentralFrequency();
String otsiPort = getLinePort(linePort);
long logicalChannelIndex;
log.info("Sending LINE FlowRule to device {} LINE port {}, frequency {}",
did(), linePort, centralFrequency);
//STEP 1: FIND logical channel
try {
logicalChannelIndex= getLogicalChannelIndex(session, otsiPort);
if(logicalChannelIndex != -1)
log.debug("Logical channel already present, skipping creation phase {}", logicalChannelIndex);
/*if(getLogicalChannelIndexState(session,logicalChannelIndex).equals(OPERATION_DISABLE)){
createLineLogicalChannel(session, otsiPort);
}*/
else
createLineLogicalChannel(session, otsiPort);
} catch (NetconfException e) {
log.error("{} Error creating the LINE logical channel for port {}", did(),
otsiPort);
}
sleepOneSecond();
//STEP 2: Set central frequency and power
try {
setOpticalChannelFrequency(session, otsiPort, centralFrequency);
log.info("Frequency for port {} set to {} THz", otsiPort, centralFrequency.asTHz());
} catch (NetconfException e) {
log.error("Error writing central frequency in the component");
return false;
}
}
//Configuration of CLIENT side, used for OpticalCircuit intents
//--- associate the client port to the line port
//--- enable the client port
//
//Assumes only one "assignment" per logical-channel with index 1
//TODO check the OTN mapping of client ports into the line port frame specified by parameter "<allocation>"
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS ||
rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
String clientPortName;
String linePortName;
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
clientPortName = getClientPort(rule.inPort());
linePortName = getLinePort(rule.outPort());
} else {
clientPortName = getClientPort(rule.outPort());
linePortName = getLinePort(rule.inPort());
}
long logicalChannelIndex;
log.info("Sending CLIENT FlowRule to device {} CLIENT port: {}, LINE port {}",
did(), clientPortName, linePortName);
//STEP 1: FIND logical channel
try {
logicalChannelIndex= getLogicalChannelIndex(session, linePortName);
if(logicalChannelIndex != -1)
log.debug("Logical channel already present, skipping creation phase {}", logicalChannelIndex);
else
createLineLogicalChannel(session, linePortName);
} catch (NetconfException e) {
log.error("{} Error creating the LINE logical channel for port {}", did(),
linePortName);
}
sleepOneSecond();
//STEP 2: SET logical channel
try {
logicalChannelIndex= getLogicalChannelIndex(session, linePortName);
setLogicalChannelAssignment(session, OPERATION_ENABLE, clientPortName, logicalChannelIndex);
} catch (NetconfException e) {
log.error("Error setting the logical channel assignment");
return false;
}
}
return true;
}
protected boolean removeFlowRule(NetconfSession session, TerminalDeviceFlowRule rule)
throws NetconfException {
//Configuration of LINE side, used for OpticalConnectivity intents
//--- configure central frequency to ZERO
//--- disable the line port
if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS ||
rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
FlowRuleParser frp = new FlowRuleParser(rule);
String componentName = getLinePort(frp.getPortNumber());
log.info("Removing LINE FlowRule device {} line port {}", did(), componentName);
long logicalChannelIndex;
try {
logicalChannelIndex = getLogicalChannelIndex(session, componentName);
deleteLogicalChannel(session,logicalChannelIndex);
} catch (NetconfException e) {
log.error("Error disabling the logical channel line side");
return false;
}
}
//Configuration of CLIENT side, used for OpticalCircuit intents
//--- configure central frequency to ZERO
//--- disable the line port
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS ||
rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
String clientPortName;
String linePortName;
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
clientPortName = getClientPort(rule.inPort());
linePortName = getLinePort(rule.outPort());
} else {
clientPortName = getClientPort(rule.inPort());
linePortName = getLinePort(rule.outPort());
}
long logicalChannelIndex;
log.debug("Removing CLIENT FlowRule device {} client port: {}, line port {}",
did(), clientPortName, linePortName);
try {
logicalChannelIndex = getLogicalChannelIndex(session, linePortName);
deleteLogicalChannelAssignment(session, clientPortName,logicalChannelIndex);
} catch (NetconfException e) {
log.error("Error disabling the logical channel assignment");
return false;
}
}
return true;
}
private List<PortNumber> getLinePorts() {
List<PortNumber> linePorts;
DeviceService deviceService = this.handler().get(DeviceService.class);
linePorts = deviceService.getPorts(data().deviceId()).stream()
.filter(p -> p.annotations().value(OdtnDeviceDescriptionDiscovery.PORT_TYPE)
.equals(OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value()))
.map(p -> p.number())
.collect(Collectors.toList());
return linePorts;
}
private String getLinePort(PortNumber portNum) {
DeviceService deviceService = this.handler().get(DeviceService.class);
return deviceService.getPort(did(),portNum)
.annotations().value(OdtnDeviceDescriptionDiscovery.OC_OPTICAL_CHANNEL);
}
private String getClientPort(PortNumber portNum) {
DeviceService deviceService = this.handler().get(DeviceService.class);
return deviceService.getPort(did(),portNum)
.annotations().value(OdtnDeviceDescriptionDiscovery.OC_TRANSCEIVER);
}
private String getIndex(String otsiPort) {
String index;
switch (otsiPort) {
case "otsi-1/1/0/E1":
index = String.valueOf(10);
break;
case "otsi-1/1/0/E2":
index = String.valueOf(20);
break;
case "otsi-1/2/0/E1":
index = String.valueOf(30);
break;
case "otsi-1/2/0/E2":
index = String.valueOf(40);
break;
default:
throw new IllegalArgumentException("Incorrect Line Port name");
}
return index;
}
private void sleepOneSecond(){
try {
Thread.sleep(1000);
}catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
}