Fixing the meter timeout issue and support transparent flows.

The related tasks:

* https://jira.opencord.org/browse/VOL-1545
* https://jira.opencord.org/browse/VOL-1571

Change-Id: I390f39a7edbd92582584747f489f198af3e9e514
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/OltPipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/OltPipeline.java
index d5b5ac1..4ccb9e3 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/OltPipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/OltPipeline.java
@@ -415,13 +415,14 @@
 
     private void installNoModificationRules(ForwardingObjective fwd) {
         Instructions.OutputInstruction output = (Instructions.OutputInstruction) fetchOutput(fwd, DOWNSTREAM);
+        Instructions.MetadataInstruction writeMetadata = fetchWriteMetadata(fwd);
+        Instructions.MeterInstruction meter = (Instructions.MeterInstruction) fetchMeter(fwd);
 
         TrafficSelector selector = fwd.selector();
 
         Criterion inport = selector.getCriterion(Criterion.Type.IN_PORT);
         Criterion outerVlan = selector.getCriterion(Criterion.Type.VLAN_VID);
         Criterion innerVlan = selector.getCriterion(Criterion.Type.INNER_VLAN_VID);
-        Criterion metadata;
 
         if (inport == null || output == null || innerVlan == null || outerVlan == null) {
             log.error("Forwarding objective is underspecified: {}", fwd);
@@ -429,15 +430,14 @@
             return;
         }
 
-        metadata = Criteria.matchMetadata(((VlanIdCriterion) innerVlan).vlanId().toShort());
 
         FlowRule.Builder outer = DefaultFlowRule.builder()
                 .fromApp(fwd.appId())
                 .forDevice(deviceId)
                 .makePermanent()
                 .withPriority(fwd.priority())
-                .withSelector(buildSelector(inport, outerVlan, metadata))
-                .withTreatment(buildTreatment(output));
+                .withSelector(buildSelector(inport, outerVlan))
+                .withTreatment(buildTreatment(output, writeMetadata, meter));
 
         applyRules(fwd, outer);
     }
diff --git a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
index 87abcd0..ce8e307 100644
--- a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
+++ b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
@@ -138,6 +138,8 @@
                 .expireAfterWrite(TIMEOUT, TimeUnit.SECONDS)
                 .removalListener((RemovalNotification<Long, MeterOperation> notification) -> {
                     if (notification.getCause() == RemovalCause.EXPIRED) {
+                        log.debug("Expired on meter provider. Meter key {} and operation {}",
+                                notification.getKey(), notification.getValue());
                         providerService.meterOperationFailed(notification.getValue(),
                                                              MeterFailReason.TIMEOUT);
                     }
@@ -205,9 +207,6 @@
 
     private void performOperation(OpenFlowSwitch sw, MeterOperation op) {
 
-        pendingOperations.put(op.meter().id().id(), op);
-
-
         Meter meter = op.meter();
         MeterModBuilder builder = MeterModBuilder.builder(meter.id().id(), sw.factory());
         if (meter.isBurst()) {
@@ -219,12 +218,14 @@
 
         switch (op.type()) {
             case ADD:
+                pendingOperations.put(op.meter().id().id(), op);
                 sw.sendMsg(builder.add());
                 break;
             case REMOVE:
                 sw.sendMsg(builder.remove());
                 break;
             case MODIFY:
+                pendingOperations.put(op.meter().id().id(), op);
                 sw.sendMsg(builder.modify());
                 break;
             default: