ONOS-6067 avoid sending FlowRule against EDFA device.

- Also exclude optical amplifier type from default no-LLDP list

Change-Id: I220d0a3cfa95d80644707cbe3395d3ed63540716
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
index 9066032..b848dc1 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
@@ -24,7 +24,12 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.Device.Type;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.DeviceServiceAdapter;
 import org.onosproject.net.flow.DefaultFlowRule;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -45,6 +50,7 @@
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Optional;
 
 @Component(immediate = true)
 public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> {
@@ -57,6 +63,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected CoreService coreService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService = new DeviceServiceAdapter();
+
     private ApplicationId appId;
 
     @Activate
@@ -91,6 +100,14 @@
         );
     }
 
+    private boolean blockFlowRule(DeviceId deviceId) {
+        Type devType = Optional.ofNullable(deviceService.getDevice(deviceId))
+                                .map(Device::type)
+                                .orElse(Device.Type.OTHER);
+        // TODO add condition for protection switch
+        return devType == Device.Type.OPTICAL_AMPLIFIER;
+    }
+
     /**
      * Create rules for the forward path of the intent.
      *
@@ -118,7 +135,9 @@
                     .makePermanent()
                     .build();
 
-            rules.add(rule);
+            if (!blockFlowRule(current.deviceId())) {
+                rules.add(rule);
+            }
 
             current = link.dst();
             selectorBuilder.matchInPort(link.dst().port());
@@ -138,7 +157,10 @@
                 .fromApp(appId)
                 .makePermanent()
                 .build();
-        rules.add(rule);
+
+        if (!blockFlowRule(intent.dst().deviceId())) {
+            rules.add(rule);
+        }
 
         return rules;
     }
@@ -170,7 +192,9 @@
                     .makePermanent()
                     .build();
 
-            rules.add(rule);
+            if (!blockFlowRule(current.deviceId())) {
+                rules.add(rule);
+            }
 
             current = link.src();
             selectorBuilder.matchInPort(link.src().port());
@@ -190,7 +214,10 @@
                 .fromApp(appId)
                 .makePermanent()
                 .build();
-        rules.add(rule);
+
+        if (!blockFlowRule(intent.src().deviceId())) {
+            rules.add(rule);
+        }
 
         return rules;
     }
diff --git a/core/api/src/test/java/org/onosproject/net/device/DeviceServiceAdapter.java b/core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java
similarity index 100%
rename from core/api/src/test/java/org/onosproject/net/device/DeviceServiceAdapter.java
rename to core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
index eddf4b4..98ae408 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
@@ -187,7 +187,10 @@
     private ApplicationId appId;
 
     static final SuppressionRules DEFAULT_RULES
-        = new SuppressionRules(EnumSet.of(Device.Type.ROADM, Device.Type.FIBER_SWITCH, Device.Type.OTN),
+        = new SuppressionRules(EnumSet.of(Device.Type.ROADM,
+                                          Device.Type.FIBER_SWITCH,
+                                          Device.Type.OPTICAL_AMPLIFIER,
+                                          Device.Type.OTN),
                                ImmutableMap.of(NO_LLDP, SuppressionRules.ANY_VALUE));
 
     private SuppressionRules rules = LldpLinkProvider.DEFAULT_RULES;