Merge "Fix errors reported by pyang"
authorEd Warnicke <eaw@cisco.com>
Mon, 9 Dec 2013 16:59:54 +0000 (16:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 9 Dec 2013 16:59:54 +0000 (16:59 +0000)
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMUtil.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/MeterConsumerImpl.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfMapping.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java
opendaylight/netconf/netconf-client/src/main/resources/client_hello.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/client_hello.xml

index 24bfc4fdf4c09079230189c43e9d33a428ab0cbf..84b3e53e065cfea03f225cc1c6fe0f8ebaa27582 100644 (file)
@@ -260,13 +260,13 @@ public class FRMUtil {
                 }
             } else if (action instanceof SetDlDstAction) {
                 MacAddress address = ((SetDlDstAction) action).getAddress();
-                if (address != null && !isL2AddressValid(address.toString())) {
+                if (address != null && !isL2AddressValid(address.getValue())) {
                     logger.error("SetDlDstAction: Address not valid");
                     return false;
                 }
             } else if (action instanceof SetDlSrcAction) {
                 MacAddress address = ((SetDlSrcAction) action).getAddress();
-                if (address != null && !isL2AddressValid(address.toString())) {
+                if (address != null && !isL2AddressValid(address.getValue())) {
                     logger.error("SetDlSrcAction: Address not valid");
                     return false;
                 }
index 19c366d014b66d5d33af1e84003c1c8f8daee256..d2f2420a7cb58814444de25af8944e57f2e80abb 100644 (file)
@@ -2,50 +2,37 @@ package org.opendaylight.controller.forwardingrulesmanager.consumer.impl;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Future;
-
-import org.opendaylight.controller.clustering.services.CacheConfigException;
-import org.opendaylight.controller.clustering.services.CacheExistException;
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;
-import org.opendaylight.controller.clustering.services.IClusterServices;
+
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.sal.common.util.Rpcs;
-import org.opendaylight.controller.sal.core.IContainer;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.config.rev131024.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.config.rev131024.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.config.rev131024.tables.TableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.config.rev131024.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -55,32 +42,13 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class FlowConsumerImpl implements IForwardingRulesManager {
+public class FlowConsumerImpl {
     protected static final Logger logger = LoggerFactory.getLogger(FlowConsumerImpl.class);
     private final FlowEventListener flowEventListener = new FlowEventListener();
     private Registration<NotificationListener> listener1Reg;
     private SalFlowService flowService;
     // private FlowDataListener listener;
-    private FlowDataCommitHandler commitHandler;
-    private static ConcurrentHashMap<FlowKey, Flow> originalSwView;
-    private static ConcurrentMap<FlowKey, Flow> installedSwView;
-    private IClusterContainerServices clusterContainerService = null;
-    private IContainer container;
-    private static final String NAMEREGEX = "^[a-zA-Z0-9]+$";
-    private static ConcurrentMap<Integer, Flow> staticFlows;
-    private static ConcurrentMap<Integer, Integer> staticFlowsOrdinal = new ConcurrentHashMap<Integer, Integer>();
-    /*
-     * Inactive flow list. This is for the global instance of FRM It will
-     * contain all the flow entries which were installed on the global container
-     * when the first container is created.
-     */
-    private static ConcurrentMap<FlowKey, Flow> inactiveFlows;
-
-    /*
-     * /* Per node indexing
-     */
-    private static ConcurrentMap<Node, List<Flow>> nodeFlows;
-    private boolean inContainerMode; // being used by global instance only
+    private FlowDataCommitHandler commitHandler;    
 
     public FlowConsumerImpl() {
         InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(Flows.class).toInstance();
@@ -90,17 +58,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
             logger.error("Consumer SAL Service is down or NULL. FRM may not function as intended");
             return;
         }
-
-        // listener = new FlowDataListener();
-
-        // if (null ==
-        // FRMConsumerImpl.getDataBrokerService().registerDataChangeListener(path,
-        // listener)) {
-        // logger.error("Failed to listen on flow data modifcation events");
-        // System.out.println("Consumer SAL Service is down or NULL.");
-        // return;
-        // }
-
+        
         // For switch events
         listener1Reg = FRMConsumerImpl.getNotificationService().registerNotificationListener(flowEventListener);
 
@@ -110,66 +68,9 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
         }
         // addFlowTest();
         commitHandler = new FlowDataCommitHandler();
-        FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, commitHandler);
-        clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(
-                IClusterContainerServices.class, this);
-        allocateCaches();
-        /*
-         * If we are not the first cluster node to come up, do not initialize
-         * the static flow entries ordinal
-         */
-        if (staticFlowsOrdinal.size() == 0) {
-            staticFlowsOrdinal.put(0, Integer.valueOf(0));
-        }
+        FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, commitHandler);        
     }
-
-    private void allocateCaches() {
-
-        if (this.clusterContainerService == null) {
-            logger.warn("Un-initialized clusterContainerService, can't create cache");
-            return;
-        }
-
-        try {
-            clusterContainerService.createCache("frm.originalSwView",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService.createCache("frm.installedSwView",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService
-                    .createCache("frm.staticFlows", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService.createCache("frm.staticFlowsOrdinal",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService.createCache("frm.inactiveFlows",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService.createCache("frm.nodeFlows", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-            clusterContainerService.createCache("frm.groupFlows", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-        } catch (CacheConfigException cce) {
-            logger.error("CacheConfigException");
-        } catch (CacheExistException cce) {
-            logger.error("CacheExistException");
-        }
-    }
-
-    private void addFlowTest() {
-        try {
-            NodeRef nodeOne = createNodeRef("foo:node:1");
-            AddFlowInputBuilder input1 = new AddFlowInputBuilder();
-
-            input1.setNode(nodeOne);
-            AddFlowInput firstMsg = input1.build();
-
-            if (null == flowService) {
-                logger.error("ConsumerFlowService is NULL");
-            }
-            @SuppressWarnings("unused")
-            Future<RpcResult<AddFlowOutput>> result1 = flowService.addFlow(firstMsg);
-
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-
+    
     /**
      * Adds flow to the southbound plugin and our internal database
      *
@@ -179,42 +80,11 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
     private void addFlow(InstanceIdentifier<?> path, Flow dataObject) {
 
         AddFlowInputBuilder input = new AddFlowInputBuilder();
-
+        input.fieldsFrom(dataObject);
         input.setNode((dataObject).getNode());
-        input.setPriority((dataObject).getPriority());
-        input.setMatch((dataObject).getMatch());
-        input.setCookie((dataObject).getCookie());
-        input.setInstructions((dataObject).getInstructions());
-        input.setBufferId(dataObject.getBufferId());
-        input.setTableId(dataObject.getTableId());
-        input.setOutPort(dataObject.getOutPort());
-        input.setOutGroup(dataObject.getOutGroup());
-        input.setIdleTimeout(dataObject.getIdleTimeout());
-        input.setHardTimeout(dataObject.getHardTimeout());
-        input.setFlowName(dataObject.getFlowName());
-        input.setFlags(dataObject.getFlags());
-        input.setCookieMask(dataObject.getCookieMask());
-        input.setContainerName(dataObject.getContainerName());
-        input.setBarrier(dataObject.isBarrier());
-        input.setInstallHw(dataObject.isInstallHw());
-        input.setStrict(dataObject.isStrict());
-
-        // updating the staticflow cache
-        /*
-         * Commented out... as in many other places... use of ClusteringServices
-         * is breaking things insufficient time to debug Integer ordinal =
-         * staticFlowsOrdinal.get(0); staticFlowsOrdinal.put(0, ++ordinal);
-         * staticFlows.put(ordinal, dataObject);
-         */
-
+        input.setFlowTable(new FlowTableRef(createTableInstance(dataObject.getId(), dataObject.getNode())));
         // We send flow to the sounthbound plugin
-
         flowService.addFlow(input.build());
-
-        /*
-         * Commented out as this will also break due to improper use of
-         * ClusteringServices updateLocalDatabase((NodeFlow) dataObject, true);
-         */
     }
 
     /**
@@ -224,41 +94,14 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
      * @param dataObject
      */
     private void removeFlow(InstanceIdentifier<?> path, Flow dataObject) {
-
+        
         RemoveFlowInputBuilder input = new RemoveFlowInputBuilder();
+        input.fieldsFrom(dataObject);
         input.setNode((dataObject).getNode());
-        input.setPriority((dataObject).getPriority());
-        input.setMatch((dataObject).getMatch());
-        input.setCookie((dataObject).getCookie());
-        input.setInstructions((dataObject).getInstructions());
-        input.setBufferId(dataObject.getBufferId());
         input.setTableId(dataObject.getTableId());
-        input.setOutPort(dataObject.getOutPort());
-        input.setOutGroup(dataObject.getOutGroup());
-        input.setIdleTimeout(dataObject.getIdleTimeout());
-        input.setHardTimeout(dataObject.getHardTimeout());
-        input.setFlowName(dataObject.getFlowName());
-        input.setFlags(dataObject.getFlags());
-        input.setCookieMask(dataObject.getCookieMask());
-        input.setContainerName(dataObject.getContainerName());
-        input.setBarrier(dataObject.isBarrier());
-        input.setInstallHw(dataObject.isInstallHw());
-        input.setStrict(dataObject.isStrict());
-        // updating the staticflow cache
-        /*
-         * Commented out due to problems caused by improper use of
-         * ClusteringServices Integer ordinal = staticFlowsOrdinal.get(0);
-         * staticFlowsOrdinal.put(0, ++ordinal); staticFlows.put(ordinal,
-         * dataObject);
-         */
-
+        input.setFlowTable(new FlowTableRef(createTableInstance((long)dataObject.getTableId(), (dataObject).getNode())));
         // We send flow to the sounthbound plugin
         flowService.removeFlow(input.build());
-
-        /*
-         * Commented out due to problems caused by improper use of
-         * ClusteringServices updateLocalDatabase((NodeFlow) dataObject, false);
-         */
     }
 
     /**
@@ -267,32 +110,19 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
      * @param path
      * @param dataObject
      */
-    private void updateFlow(InstanceIdentifier<?> path, Flow dataObject) {
+    private void updateFlow(InstanceIdentifier<?> path, Flow updatedFlow, Flow originalFlow) {
 
         UpdateFlowInputBuilder input = new UpdateFlowInputBuilder();
         UpdatedFlowBuilder updatedflowbuilder = new UpdatedFlowBuilder();
-        updatedflowbuilder.fieldsFrom(dataObject);
-        input.setNode(dataObject.getNode());
-        input.setUpdatedFlow(updatedflowbuilder.build());
-
-        // updating the staticflow cache
-        /*
-         * Commented out due to problems caused by improper use of
-         * ClusteringServices. Integer ordinal = staticFlowsOrdinal.get(0);
-         * staticFlowsOrdinal.put(0, ++ordinal); staticFlows.put(ordinal,
-         * dataObject);
-         */
-
+        updatedflowbuilder.fieldsFrom(updatedFlow);
+        input.setNode(updatedFlow.getNode());
+        input.setUpdatedFlow(updatedflowbuilder.build());  
+        OriginalFlowBuilder ofb = new OriginalFlowBuilder(originalFlow);
+        input.setOriginalFlow(ofb.build());
         // We send flow to the sounthbound plugin
         flowService.updateFlow(input.build());
-
-        /*
-         * Commented out due to problems caused by improper use of
-         * ClusteringServices. updateLocalDatabase((NodeFlow) dataObject, true);
-         */
     }
-
-    @SuppressWarnings("unchecked")
     private void commitToPlugin(internalTransaction transaction) {
         Set<Entry<InstanceIdentifier<?>, DataObject>> createdEntries = transaction.getModification()
                 .getCreatedConfigurationData().entrySet();
@@ -320,16 +150,17 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
                 addFlow(entry.getKey(), (Flow) entry.getValue());
             }
         }
-        for (@SuppressWarnings("unused")
-        Entry<InstanceIdentifier<?>, DataObject> entry : updatedEntries) {
+       
+        for (Entry<InstanceIdentifier<?>, DataObject> entry : updatedEntries) {
             if (entry.getValue() instanceof Flow) {
                 logger.debug("Coming update cc in FlowDatacommitHandler");
-                Flow flow = (Flow) entry.getValue();
-                boolean status = validate(flow);
+                Flow updatedFlow = (Flow) entry.getValue();
+                Flow originalFlow = (Flow) transaction.modification.getOriginalConfigurationData().get(entry.getKey());
+                boolean status = validate(updatedFlow);
                 if (!status) {
                     return;
                 }
-                updateFlow(entry.getKey(), (Flow) entry.getValue());
+                updateFlow(entry.getKey(), updatedFlow, originalFlow);
             }
         }
 
@@ -339,21 +170,20 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
                 logger.debug("Coming remove cc in FlowDatacommitHandler");
                 Flow flow = (Flow) removeValue;
                 boolean status = validate(flow);
+                
                 if (!status) {
                     return;
                 }
+                
                 removeFlow(instanceId, (Flow) removeValue);
-
             }
         }
-
     }
 
-    private final class FlowDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {
-
+    private final class FlowDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {   
+     
         @SuppressWarnings("unchecked")
-        @Override
-        public DataCommitTransaction requestCommit(DataModification<InstanceIdentifier<?>, DataObject> modification) {
+        public DataCommitTransaction<InstanceIdentifier<?>, DataObject> requestCommit(DataModification<InstanceIdentifier<?>, DataObject> modification) {
             // We should verify transaction
             logger.debug("Coming in FlowDatacommitHandler");
             internalTransaction transaction = new internalTransaction(modification);
@@ -374,54 +204,23 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
         public internalTransaction(DataModification<InstanceIdentifier<?>, DataObject> modification) {
             this.modification = modification;
         }
-
-        Map<InstanceIdentifier<?>, Flow> additions = new HashMap<>();
-        Map<InstanceIdentifier<?>, Flow> updates = new HashMap<>();
-        Map<InstanceIdentifier<?>, Flow> removals = new HashMap<>();
-
+        
         /**
          * We create a plan which flows will be added, which will be updated and
          * which will be removed based on our internal state.
          *
          */
-        void prepareUpdate() {
+        void prepareUpdate() {          
 
-            Set<Entry<InstanceIdentifier<?>, DataObject>> puts = modification.getUpdatedConfigurationData().entrySet();
-            for (Entry<InstanceIdentifier<?>, DataObject> entry : puts) {
-            }
-
-            // removals = modification.getRemovedConfigurationData();
-            Set<InstanceIdentifier<?>> removedData = modification.getRemovedConfigurationData();
-            for (InstanceIdentifier<?> removal : removedData) {
-                DataObject value = modification.getOriginalConfigurationData().get(removal);
-                if (value instanceof Flow) {
-                    removals.put(removal, (Flow) value);
-                }
-            }
-
-        }
-
-        private void preparePutEntry(InstanceIdentifier<?> key, Flow flow) {
-            Flow original = originalSwView.get(key);
-            if (original != null) {
-                // It is update for us
-                updates.put(key, flow);
-            } else {
-                // It is addition for us
-                additions.put(key, flow);
-            }
         }
-
+       
         /**
          * We are OK to go with execution of plan
          *
          */
         @Override
         public RpcResult<Void> finish() throws IllegalStateException {
-
-            commitToPlugin(this);
-            // We return true if internal transaction is successful.
-            // return Rpcs.getRpcResult(true, null, Collections.emptySet());
+            commitToPlugin(this);            
             return Rpcs.getRpcResult(true, null, Collections.<RpcError> emptySet());
         }
 
@@ -431,26 +230,47 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
          *
          */
         @Override
-        public RpcResult<Void> rollback() throws IllegalStateException {
-            // NOOP - we did not modified any internal state during
-            // requestCommit phase
-            // return Rpcs.getRpcResult(true, null, Collections.emptySet());
+        public RpcResult<Void> rollback() throws IllegalStateException {       
+            rollBackFlows(modification);
             return Rpcs.getRpcResult(true, null, Collections.<RpcError> emptySet());
 
-        }
+        }       
+    }
 
-        private boolean flowEntryExists(Flow flow) {
-            // Flow name has to be unique on per table id basis
-            for (ConcurrentMap.Entry<FlowKey, Flow> entry : originalSwView.entrySet()) {
-                if (entry.getValue().getFlowName().equals(flow.getFlowName())
-                        && entry.getValue().getTableId().equals(flow.getTableId())) {
-                    return true;
-                }
-            }
-            return false;
+    private void rollBackFlows(DataModification<InstanceIdentifier<?>, DataObject> modification) {
+     Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> createdEntries = modification.getCreatedConfigurationData().entrySet();
+
+    /*
+     * This little dance is because updatedEntries contains both created and modified entries
+     * The reason I created a new HashSet is because the collections we are returned are immutable.
+     */
+    Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updatedEntries = new HashSet<Entry<InstanceIdentifier<? extends DataObject>, DataObject>>();
+    updatedEntries.addAll(modification.getUpdatedConfigurationData().entrySet());
+    updatedEntries.removeAll(createdEntries);
+
+    Set<InstanceIdentifier<? >> removeEntriesInstanceIdentifiers = modification.getRemovedConfigurationData();
+    for (Entry<InstanceIdentifier<?>, DataObject> entry : createdEntries) {
+        if(entry.getValue() instanceof Flow) {
+            removeFlow(entry.getKey(),(Flow) entry.getValue()); // because we are rolling back, remove what we would have added.
         }
     }
+    
+    for (Entry<InstanceIdentifier<?>, DataObject> entry : updatedEntries) {
+        if(entry.getValue() instanceof Flow) {            
+            Flow updatedFlow = (Flow) entry.getValue();
+            Flow originalFlow = (Flow) modification.getOriginalConfigurationData().get(entry.getKey());
+            updateFlow(entry.getKey(), updatedFlow ,originalFlow);// because we are rolling back, replace the updated with the original
+        }
+    }
+
+    for (InstanceIdentifier<?> instanceId : removeEntriesInstanceIdentifiers ) {
+        DataObject removeValue = (Flow) modification.getOriginalConfigurationData().get(instanceId);
+        if(removeValue instanceof Flow) {
+            addFlow(instanceId,(Flow) removeValue);// because we are rolling back, add what we would have removed.
 
+        }
+    }
+}
     final class FlowEventListener implements SalFlowListener {
 
         List<FlowAdded> addedFlows = new ArrayList<>();
@@ -489,58 +309,18 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
             // TODO Auto-generated method stub
 
         }
-
     }
 
-    // Commented out DataChangeListene - to be used by Stats
-
-    // final class FlowDataListener implements DataChangeListener {
-    // private SalFlowService flowService;
-    //
-    // public FlowDataListener() {
-    //
-    // }
-    //
-    // @Override
-    // public void onDataChanged(
-    // DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-    // System.out.println("Coming in onDataChange..............");
-    // @SuppressWarnings("unchecked")
-    // Collection<DataObject> additions = (Collection<DataObject>)
-    // change.getCreatedConfigurationData();
-    // // we can check for getCreated, getDeleted or getUpdated from DataChange
-    // Event class
-    // for (DataObject dataObject : additions) {
-    // if (dataObject instanceof NodeFlow) {
-    // NodeRef nodeOne = createNodeRef("foo:node:1");
-    // // validating the dataObject here
-    // AddFlowInputBuilder input = new AddFlowInputBuilder();
-    // input.setNode(((NodeFlow) dataObject).getNode());
-    // input.setNode(nodeOne);
-    // // input.setPriority(((NodeFlow) dataObject).getPriority());
-    // //input.setMatch(((NodeFlow) dataObject).getMatch());
-    // //input.setFlowTable(((NodeFlow) dataObject).getFlowTable());
-    // //input.setCookie(((NodeFlow) dataObject).getCookie());
-    // //input.setAction(((NodeFlow) dataObject).getAction());
-    //
-    // @SuppressWarnings("unused")
-    // Future<RpcResult<java.lang.Void>> result =
-    // flowService.addFlow(input.build());
-    // }
-    // }
-    // }
-    // }
-
     public boolean validate(Flow flow) {
-
         String msg = ""; // Specific part of warn/error log
 
         boolean result = true;
         // flow Name validation
-        if (flow.getFlowName() == null || flow.getFlowName().trim().isEmpty() || !flow.getFlowName().matches(NAMEREGEX)) {
+        if (!FRMUtil.isNameValid(flow.getFlowName())) {
             msg = "Invalid Flow name";
             result = false;
         }
+        
         // Node Validation
         if (result == true && flow.getNode() == null) {
             msg = "Node is null";
@@ -556,20 +336,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
                 result = false;
             }
         }
-
-        // Presence check
-        /*
-         * This is breaking due to some improper use of caches...
-         *
-         * if (flowEntryExists(flow)) { String error =
-         * "Entry with this name on specified table already exists";
-         * logger.warn(
-         * "Entry with this name on specified table already exists: {}" ,
-         * entry); logger.error(error); return; } if
-         * (originalSwView.containsKey(entry)) { logger.warn(
-         * "Operation Rejected: A flow with same match and priority exists on the target node"
-         * ); logger.trace("Aborting to install {}", entry); continue; }
-         */
+       
         if (!FRMUtil.validateMatch(flow)) {
             logger.error("Not a valid Match");
             result = false;
@@ -584,92 +351,15 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
         }
         return result;
     }
-
-    private static void updateLocalDatabase(NodeFlow entry, boolean add) {
-
-        updateSwViewes(entry, add);
-
-        updateNodeFlowsDB(entry, add);
-
-    }
-
-    /*
-     * Update the node mapped flows database
-     */
-    private static void updateSwViewes(NodeFlow entry, boolean add) {
-        if (add) {
-            FlowConsumerImpl.originalSwView.put((FlowKey) entry, (Flow) entry);
-            installedSwView.put((FlowKey) entry, (Flow) entry);
-        } else {
-            originalSwView.remove(entry);
-            installedSwView.remove(entry);
-
-        }
-    }
-
-    @Override
-    public List<DataObject> get() {
-
-        List<DataObject> orderedList = new ArrayList<DataObject>();
-        ConcurrentMap<Integer, Flow> flowMap = staticFlows;
-        int maxKey = staticFlowsOrdinal.get(0).intValue();
-        for (int i = 0; i <= maxKey; i++) {
-            Flow entry = flowMap.get(i);
-            if (entry != null) {
-                orderedList.add(entry);
-            }
-        }
-        return orderedList;
-    }
-
-    @Override
-    public DataObject getWithName(String name, org.opendaylight.controller.sal.core.Node n) {
-        if (this instanceof FlowConsumerImpl) {
-            for (ConcurrentMap.Entry<Integer, Flow> flowEntry : staticFlows.entrySet()) {
-                Flow flow = flowEntry.getValue();
-                if (flow.getNode().equals(n) && flow.getFlowName().equals(name)) {
-
-                    return flowEntry.getValue();
-                }
-            }
-        }
-        return null;
-    }
-
-    /*
-     * Update the node mapped flows database
-     */
-    private static void updateNodeFlowsDB(NodeFlow entry, boolean add) {
-        Node node = (Node) entry.getNode();
-
-        List<Flow> nodeIndeces = nodeFlows.get(node);
-        if (nodeIndeces == null) {
-            if (!add) {
-                return;
-            } else {
-                nodeIndeces = new ArrayList<Flow>();
-            }
-        }
-
-        if (add) {
-            nodeIndeces.add((Flow) entry);
-        } else {
-            nodeIndeces.remove(entry);
-        }
-
-        // Update cache across cluster
-        if (nodeIndeces.isEmpty()) {
-            nodeFlows.remove(node);
-        } else {
-            nodeFlows.put(node, nodeIndeces);
-        }
-    }
-
-    private static NodeRef createNodeRef(String string) {
-        NodeKey key = new NodeKey(new NodeId(string));
-        InstanceIdentifier<Node> path = InstanceIdentifier.builder().node(Nodes.class).node(Node.class, key)
-                .toInstance();
-
-        return new NodeRef(path);
+    
+    private InstanceIdentifier<?> createTableInstance(Long tableId, NodeRef nodeRef) {        
+        Table table;
+        InstanceIdentifier<Table> tableInstance;
+        TableBuilder builder = new TableBuilder();
+        builder.setId(tableId);
+        builder.setKey(new TableKey(tableId, nodeRef));
+        table = builder.build();
+        tableInstance = InstanceIdentifier.builder(Tables.class).child(Table.class, table.getKey()).toInstance();
+        return tableInstance;
     }
 }
\ No newline at end of file
index 6fbbd4d6e289ce87de6f3ee0e9b119fdaa795e5b..f4064f22ceeeda56740468d11451da999d6a1a5d 100644 (file)
@@ -132,25 +132,22 @@ public class GroupConsumerImpl {
      * @param dataObject
      */
     private void updateGroup(InstanceIdentifier<?> path, 
-        Group originalGroupDataObject, Group updatedGroupDataObject) {
-        
-        GroupKey groupKey = updatedGroupDataObject.getKey();
-       // Node nodeInstanceID = path.firstIdentifierOf("Node");
+        Group updatedGroupDataObject, Group originalGroupDataObject) {
         UpdatedGroupBuilder updateGroupBuilder = null;
         Status groupOperationStatus = validateGroup(updatedGroupDataObject);
-
+        
         if (!groupOperationStatus.isSuccess()) {
             logger.error("Group data object validation failed %s" + updatedGroupDataObject.getGroupName());
             return;
         }
         
-        UpdateGroupInputBuilder groupInputBuilder = new UpdateGroupInputBuilder();
+        UpdateGroupInputBuilder groupInputBuilder = new UpdateGroupInputBuilder();        
+        updateGroupBuilder = new UpdatedGroupBuilder(updatedGroupDataObject);        
+        updateGroupBuilder.setGroupId(new GroupId(updatedGroupDataObject.getId())); 
         groupInputBuilder.setNode(updatedGroupDataObject.getNode());
-        updateGroupBuilder = new UpdatedGroupBuilder(updatedGroupDataObject);
-        updateGroupBuilder.setGroupId(new GroupId(updatedGroupDataObject.getId()));        
         groupInputBuilder.setUpdatedGroup(updateGroupBuilder.build());       
         OriginalGroupBuilder originalGroupBuilder = new OriginalGroupBuilder(originalGroupDataObject);
-        groupInputBuilder.setOriginalGroup(originalGroupBuilder.build());
+        groupInputBuilder.setOriginalGroup(originalGroupBuilder.build());     
         groupService.updateGroup(groupInputBuilder.build());
         return;
     }
@@ -171,10 +168,8 @@ public class GroupConsumerImpl {
         }
         
         AddGroupInputBuilder groupData = new AddGroupInputBuilder();
-        groupData.setBuckets(groupAddDataObject.getBuckets());
-        groupData.setContainerName(groupAddDataObject.getContainerName());
-        groupData.setGroupId(new GroupId(groupAddDataObject.getId()));
-        groupData.setGroupType(groupAddDataObject.getGroupType());
+        groupData.fieldsFrom(groupAddDataObject);       
+        groupData.setGroupId(new GroupId(groupAddDataObject.getId()));     
         groupData.setNode(groupAddDataObject.getNode());    
         groupService.addGroup(groupData.build());
         return;
@@ -196,11 +191,9 @@ public class GroupConsumerImpl {
         }
        
         RemoveGroupInputBuilder groupData = new RemoveGroupInputBuilder();
-        groupData.setBuckets(groupRemoveDataObject.getBuckets());
-        groupData.setContainerName(groupRemoveDataObject.getContainerName());
-        groupData.setGroupId(new GroupId(groupRemoveDataObject.getId()));
-        groupData.setGroupType(groupRemoveDataObject.getGroupType());
-        groupData.setNode(groupRemoveDataObject.getNode());    
+        groupData.fieldsFrom(groupRemoveDataObject);
+        groupData.setGroupId(new GroupId(groupRemoveDataObject.getId()));    
+        groupData.setNode(groupRemoveDataObject.getNode());
         groupService.removeGroup(groupData.build());  
         return;
     }
index 42d0897fb11ae85182f6a87e83f3015e191f716c..bf8c8b7f05b912b3075c81a52a1f978fb76a284f 100644 (file)
@@ -27,6 +27,13 @@ import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.config.rev131024.Meters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.config.rev131024.meters.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.config.rev131024.meters.MeterKey;
@@ -38,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Rem
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.BandType;
@@ -53,35 +61,17 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class MeterConsumerImpl implements IForwardingRulesManager {
+public class MeterConsumerImpl {
     protected static final Logger logger = LoggerFactory.getLogger(MeterConsumerImpl.class);
     private final MeterEventListener meterEventListener = new MeterEventListener();
     private Registration<NotificationListener> meterListener;
     private SalMeterService meterService;
     private MeterDataCommitHandler commitHandler;
 
-    private ConcurrentMap<MeterKey, Meter> originalSwMeterView;
-    @SuppressWarnings("unused")
-    private ConcurrentMap<MeterKey, Meter> installedSwMeterView;
-    @SuppressWarnings("unused")
-    private ConcurrentMap<Node, List<Meter>> nodeMeters;
-    @SuppressWarnings("unused")
-    private ConcurrentMap<MeterKey, Meter> inactiveMeters;
-    @SuppressWarnings("unused")
-    private IContainer container;
-    private IClusterContainerServices clusterMeterContainerService = null;    
-
     public MeterConsumerImpl() {
         InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(Meters.class).toInstance();
         meterService = FRMConsumerImpl.getProviderSession().getRpcService(SalMeterService.class);
-        clusterMeterContainerService = FRMConsumerImpl.getClusterContainerService();
-        container = FRMConsumerImpl.getContainer();
-
-        if (!(cacheStartup())) {
-            logger.error("Unable to allocate/retrieve meter cache");
-            System.out.println("Unable to allocate/retrieve meter cache");
-        }
-
+        
         if (null == meterService) {
             logger.error("Consumer SAL Meter Service is down or NULL. FRM may not function as intended");
             System.out.println("Consumer SAL Meter Service is down or NULL.");
@@ -100,110 +90,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         commitHandler = new MeterDataCommitHandler();
         FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, commitHandler);
     }
-
-    private boolean allocateMeterCaches() {
-        if (this.clusterMeterContainerService == null) {
-            logger.warn("Meter: Un-initialized clusterMeterContainerService, can't create cache");
-            return false;
-        }
-
-        try {
-            clusterMeterContainerService.createCache("frm.originalSwMeterView",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
-            clusterMeterContainerService.createCache("frm.installedSwMeterView",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
-            clusterMeterContainerService.createCache("frm.inactiveMeters",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
-            clusterMeterContainerService.createCache("frm.nodeMeters",
-                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
-            // TODO for cluster mode
-            /*
-             * clusterMeterContainerService.createCache(WORK_STATUS_CACHE,
-             * EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
-             * IClusterServices.cacheMode.ASYNC));
-             *
-             * clusterMeterContainerService.createCache(WORK_ORDER_CACHE,
-             * EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
-             * IClusterServices.cacheMode.ASYNC));
-             */
-
-        } catch (CacheConfigException cce) {
-            logger.error("Meter CacheConfigException");
-            return false;
-
-        } catch (CacheExistException cce) {
-            logger.error(" Meter CacheExistException");
-        }
-
-        return true;
-    }
-
-    private void nonClusterMeterObjectCreate() {
-        originalSwMeterView = new ConcurrentHashMap<MeterKey, Meter>();
-        installedSwMeterView = new ConcurrentHashMap<MeterKey, Meter>();
-        nodeMeters = new ConcurrentHashMap<Node, List<Meter>>();
-        inactiveMeters = new ConcurrentHashMap<MeterKey, Meter>();
-    }
-
-    @SuppressWarnings({ "unchecked" })
-    private boolean retrieveMeterCaches() {
-        ConcurrentMap<?, ?> map;
-
-        if (this.clusterMeterContainerService == null) {
-            logger.warn("Meter: un-initialized clusterMeterContainerService, can't retrieve cache");
-            nonClusterMeterObjectCreate();
-            return false;
-        }
-
-        map = clusterMeterContainerService.getCache("frm.originalSwMeterView");
-        if (map != null) {
-            originalSwMeterView = (ConcurrentMap<MeterKey, Meter>) map;
-        } else {
-            logger.error("Retrieval of cache(originalSwMeterView) failed");
-            return false;
-        }
-
-        map = clusterMeterContainerService.getCache("frm.installedSwMeterView");
-        if (map != null) {
-            installedSwMeterView = (ConcurrentMap<MeterKey, Meter>) map;
-        } else {
-            logger.error("Retrieval of cache(installedSwMeterView) failed");
-            return false;
-        }
-
-        map = clusterMeterContainerService.getCache("frm.inactiveMeters");
-        if (map != null) {
-            inactiveMeters = (ConcurrentMap<MeterKey, Meter>) map;
-        } else {
-            logger.error("Retrieval of cache(inactiveMeters) failed");
-            return false;
-        }
-
-        map = clusterMeterContainerService.getCache("frm.nodeMeters");
-        if (map != null) {
-            nodeMeters = (ConcurrentMap<Node, List<Meter>>) map;
-        } else {
-            logger.error("Retrieval of cache(nodeMeter) failed");
-            return false;
-        }
-
-        return true;
-    }
-
-    private boolean cacheStartup() {
-        if (allocateMeterCaches()) {
-            if (retrieveMeterCaches()) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
+    
     /**
      * Adds Meter to the southbound plugin and our internal database
      *
@@ -213,11 +100,9 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
     private Status addMeter(InstanceIdentifier<?> path, Meter meterAddDataObject) {
         MeterKey meterKey = meterAddDataObject.getKey();
         
-        if (null != meterKey && validateMeter(meterAddDataObject, FRMUtil.operation.ADD).isSuccess()) {                 
+        if (null != meterKey && validateMeter(meterAddDataObject).isSuccess()) {                
             AddMeterInputBuilder meterBuilder = new AddMeterInputBuilder();
-            meterBuilder.setContainerName(meterAddDataObject.getContainerName());
-            meterBuilder.setFlags(meterAddDataObject.getFlags());
-            meterBuilder.setMeterBandHeaders(meterAddDataObject.getMeterBandHeaders());
+            meterBuilder.fieldsFrom(meterAddDataObject);            
             meterBuilder.setMeterId(new MeterId(meterAddDataObject.getId()));
             meterBuilder.setNode(meterAddDataObject.getNode());           
             meterService.addMeter(meterBuilder.build());
@@ -235,16 +120,19 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
      *
      * @param dataObject
      */
-    private Status updateMeter(InstanceIdentifier<?> path, Meter meterUpdateDataObject) {
-        MeterKey meterKey = meterUpdateDataObject.getKey();
+    private Status updateMeter(InstanceIdentifier<?> path, 
+                Meter updatedMeter, Meter originalMeter) {        
         UpdatedMeterBuilder updateMeterBuilder = null;
         
-        if (null != meterKey && validateMeter(meterUpdateDataObject, FRMUtil.operation.UPDATE).isSuccess()) {                UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
+        if (validateMeter(updatedMeter).isSuccess()) {                
+            UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
+            updateMeterInputBuilder.setNode(updatedMeter.getNode());
             updateMeterBuilder = new UpdatedMeterBuilder();
-            updateMeterBuilder.fieldsFrom(meterUpdateDataObject);
-            updateMeterBuilder.setMeterId(new MeterId(meterUpdateDataObject.getId()));
-            
+            updateMeterBuilder.fieldsFrom(updatedMeter);            
+            updateMeterBuilder.setMeterId(new MeterId(updatedMeter.getId()));            
             updateMeterInputBuilder.setUpdatedMeter(updateMeterBuilder.build());
+            OriginalMeterBuilder originalMeterBuilder = new OriginalMeterBuilder(originalMeter);
+            updateMeterInputBuilder.setOriginalMeter(originalMeterBuilder.build());
             meterService.updateMeter(updateMeterInputBuilder.build());
         } else {
             return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
@@ -263,14 +151,11 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
     private Status removeMeter(InstanceIdentifier<?> path, Meter meterRemoveDataObject) {
         MeterKey meterKey = meterRemoveDataObject.getKey();
 
-        if (null != meterKey && validateMeter(meterRemoveDataObject, FRMUtil.operation.DELETE).isSuccess()) {            
+        if (null != meterKey && validateMeter(meterRemoveDataObject).isSuccess()) {            
             RemoveMeterInputBuilder meterBuilder = new RemoveMeterInputBuilder();
-            meterBuilder.setContainerName(meterRemoveDataObject.getContainerName());
-            meterBuilder.setNode(meterRemoveDataObject.getNode());
-            meterBuilder.setFlags(meterRemoveDataObject.getFlags());
-            meterBuilder.setMeterBandHeaders(meterRemoveDataObject.getMeterBandHeaders());
-            meterBuilder.setMeterId(new MeterId(meterRemoveDataObject.getId()));
-            meterBuilder.setNode(meterRemoveDataObject.getNode());        
+            meterBuilder.fieldsFrom(meterRemoveDataObject);
+            meterBuilder.setNode(meterRemoveDataObject.getNode());            
+            meterBuilder.setMeterId(new MeterId(meterRemoveDataObject.getId()));           
             meterService.removeMeter(meterBuilder.build());
         } else {
             return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
@@ -279,22 +164,11 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         return new Status(StatusCode.SUCCESS);
     }
 
-    public Status validateMeter(Meter meter, FRMUtil.operation operation) {
-        String containerName;
+    public Status validateMeter(Meter meter) {        
         String meterName;
         Status returnStatus = null;
 
         if (null != meter) {
-            containerName = meter.getContainerName();
-
-            if (null == containerName) {
-                containerName = GlobalConstants.DEFAULT.toString();
-            } else if (!FRMUtil.isNameValid(containerName)) {
-                logger.error("Container Name is invalid %s" + containerName);
-                returnStatus = new Status(StatusCode.BADREQUEST, "Container Name is invalid");
-                return returnStatus;
-            }
-
             meterName = meter.getMeterName();
             if (!FRMUtil.isNameValid(meterName)) {
                 logger.error("Meter Name is invalid %s" + meterName);
@@ -303,7 +177,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
             }
 
             for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
-                if (!meter.getFlags().isMeterBurst()) {
+                if (null != meter.getFlags() && !meter.getFlags().isMeterBurst()) {
                     if (0 < meter.getMeterBandHeaders().getMeterBandHeader().get(i).getBurstSize()) {
                         logger.error("Burst size should only be associated when Burst FLAG is set");
                         returnStatus = new Status(StatusCode.BADREQUEST,
@@ -315,7 +189,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
 
             if (null != returnStatus && !returnStatus.isSuccess()) {
                 return returnStatus;
-            } else {
+            } else if (null != meter.getMeterBandHeaders()) {
                 BandType setBandType = null;
                 DscpRemark dscpRemark = null;
                 for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
@@ -338,6 +212,47 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         return new Status(StatusCode.SUCCESS);
     }
 
+    private RpcResult<Void> commitToPlugin(InternalTransaction transaction) {
+        DataModification<InstanceIdentifier<?>, DataObject> modification = transaction.modification;         
+        //get created entries      
+        Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> createdEntries = 
+                                        modification.getCreatedConfigurationData().entrySet();
+        
+        //get updated entries
+        Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updatedEntries = 
+                    new HashSet<Entry<InstanceIdentifier<? extends DataObject>, DataObject>>(); 
+        
+        updatedEntries.addAll(modification.getUpdatedConfigurationData().entrySet());
+        updatedEntries.removeAll(createdEntries);
+
+        //get removed entries
+        Set<InstanceIdentifier<? extends DataObject>> removeEntriesInstanceIdentifiers = 
+                                                    modification.getRemovedConfigurationData();
+        
+        for (Entry<InstanceIdentifier<? extends DataObject >, DataObject> entry : createdEntries) { 
+            if(entry.getValue() instanceof Meter) {   
+                addMeter(entry.getKey(), (Meter)entry.getValue());   
+            }   
+        } 
+        
+        for (Entry<InstanceIdentifier<?>, DataObject> entry : updatedEntries) { 
+            if(entry.getValue() instanceof Meter) {   
+                Meter originalMeter = (Meter) modification.getOriginalConfigurationData().get(entry.getKey());    
+                Meter updatedMeter = (Meter) entry.getValue(); 
+                updateMeter(entry.getKey(), originalMeter, updatedMeter);   
+            }   
+        }   
+
+        for (InstanceIdentifier<?> instanceId : removeEntriesInstanceIdentifiers ) {    
+            DataObject removeValue = modification.getOriginalConfigurationData().get(instanceId);   
+            if(removeValue instanceof Meter) {   
+                removeMeter(instanceId, (Meter)removeValue); 
+            }   
+        }
+
+        return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
+    }
+    
     final class InternalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
 
         private final DataModification<InstanceIdentifier<?>, DataObject> modification;
@@ -351,38 +266,13 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
             this.modification = modification;
         }
 
-        Map<InstanceIdentifier<?>, Meter> additions = new HashMap<>();
-        Map<InstanceIdentifier<?>, Meter> updates = new HashMap<>();
-        Set<InstanceIdentifier<?>> removals = new HashSet<>();
-
         /**
          * We create a plan which flows will be added, which will be updated and
          * which will be removed based on our internal state.
          *
          */
-        void prepareUpdate() {
-            
-            Set<Entry<InstanceIdentifier<?>, DataObject>> addMeter = modification.getCreatedConfigurationData().entrySet();
-            for (Entry<InstanceIdentifier<?>, DataObject> entry : addMeter) {
-                if (entry.getValue() instanceof Meter) {
-                    Meter meter = (Meter) entry.getValue();
-                    additions.put(entry.getKey(), meter);                    
-                }
-
-            }
+        void prepareUpdate() {           
             
-            Set<Entry<InstanceIdentifier<?>, DataObject>> updateMeter = modification.getUpdatedConfigurationData().entrySet();
-            for (Entry<InstanceIdentifier<?>, DataObject> entry : updateMeter) {
-                if (entry.getValue() instanceof Meter) {
-                    Meter meter = (Meter) entry.getValue();
-                  ///will be fixed once getUpdatedConfigurationData returns only updated data not created data with it.
-                    if (!additions.containsKey(entry.getKey())) {
-                       updates.put(entry.getKey(), meter);       
-                    }
-                }
-            }
-
-            removals = modification.getRemovedConfigurationData();
         }
 
         /**
@@ -392,9 +282,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         @Override
         public RpcResult<Void> finish() throws IllegalStateException {
 
-            RpcResult<Void> rpcStatus = commitToPlugin(this);
-            // We return true if internal transaction is successful.
-            // return Rpcs.getRpcResult(true, null, Collections.emptySet());
+            RpcResult<Void> rpcStatus = commitToPlugin(this);           
             return rpcStatus;
         }
 
@@ -404,43 +292,13 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
          *
          */
         @Override
-        public RpcResult<Void> rollback() throws IllegalStateException {
-            // NOOP - we did not modified any internal state during
-            // requestCommit phase
-            // return Rpcs.getRpcResult(true, null, Collections.emptySet());
+        public RpcResult<Void> rollback() throws IllegalStateException {            
             return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
 
         }
 
     }
     
-    private RpcResult<Void> commitToPlugin(InternalTransaction transaction) {
-        for (Entry<InstanceIdentifier<?>, Meter> entry : transaction.additions.entrySet()) {
-
-            if (!addMeter(entry.getKey(), entry.getValue()).isSuccess()) {
-                return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
-            }
-        }
-        for (Entry<InstanceIdentifier<?>, Meter> entry : transaction.updates.entrySet()) {
-
-            if (!updateMeter(entry.getKey(), entry.getValue()).isSuccess()) {
-                return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
-            }
-        }
-
-        for (InstanceIdentifier<?> meterId : transaction.removals) {
-            DataObject removeValue = transaction.getModification().getOriginalConfigurationData().get(meterId);        
-                
-                if(removeValue instanceof Meter) {
-                    if(!removeMeter(meterId, (Meter)removeValue).isSuccess()) {
-                        return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
-                        }
-                }    
-        }
-
-        return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
-    }
-
     private final class MeterDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {
         @Override
         public org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction<InstanceIdentifier<?>, DataObject> requestCommit(
@@ -475,32 +333,5 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
             // TODO Auto-generated method stub
 
         }
-    }
-
-    @Override
-    public List<DataObject> get() {
-
-        List<DataObject> orderedList = new ArrayList<DataObject>();
-        Collection<Meter> meterList = originalSwMeterView.values();
-        for (Iterator<Meter> iterator = meterList.iterator(); iterator.hasNext();) {
-            orderedList.add(iterator.next());
-        }
-        return orderedList;
-    }
-
-    @Override
-    public DataObject getWithName(String name, Node n) {
-        if (this instanceof MeterConsumerImpl) {
-            Collection<Meter> meterList = originalSwMeterView.values();
-            for (Iterator<Meter> iterator = meterList.iterator(); iterator.hasNext();) {
-                Meter meter = iterator.next();
-                if (meter.getNode().equals(n) && meter.getMeterName().equals(name)) {
-
-                    return meter;
-                }
-            }
-        }
-        
-        return null;
-    }
+    }   
 }
index 4d0a1ac6b663e3ecf7aee035ab5b47157de1aed8..55a1fbfe486a03f033ba961586675cb21beea2d6 100644 (file)
@@ -10,6 +10,7 @@
 package org.opendaylight.controller.config.yang.md.sal.connector.netconf;
 
 import io.netty.channel.EventLoopGroup;
+import io.netty.util.concurrent.GlobalEventExecutor;
 
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -21,6 +22,8 @@ import org.opendaylight.controller.netconf.client.NetconfSshClientDispatcher;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.TimedReconnectStrategy;
 import org.osgi.framework.BundleContext;
 
 import static com.google.common.base.Preconditions.*;
@@ -62,6 +65,8 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         String addressValue = getAddress();
         
         
+        int attemptMsTimeout = 60*1000;
+        int connectionAttempts = 5;
         /*
          * Uncomment after Switch to IP Address
         if(getAddress().getIpv4Address() != null) {
@@ -71,6 +76,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         }
         
         */
+        ReconnectStrategy strategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, attemptMsTimeout, 1000, 1.0, null,
+                Long.valueOf(connectionAttempts), null);
+        
+        
+        device.setStrategy(strategy);
+        
         InetAddress addr = InetAddresses.forString(addressValue);
         InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
         device.setSocketAddress(socketAddress);
index 49d9757f421058cb05ffed90f81922f6509ff688..7c4bf5facad6a3dd94b0f1bd6a73e301a7820143 100644 (file)
@@ -22,8 +22,16 @@ import org.opendaylight.controller.sal.core.api.data.DataBrokerService
 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction
 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl
+import org.opendaylight.protocol.framework.ReconnectStrategy
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler
+import org.opendaylight.controller.md.sal.common.api.data.DataModification
 
-class NetconfDevice implements Provider, DataReader<InstanceIdentifier, CompositeNode>, RpcImplementation, AutoCloseable {
+class NetconfDevice implements 
+    Provider, // 
+    DataReader<InstanceIdentifier, CompositeNode>, //
+    DataCommitHandler<InstanceIdentifier, CompositeNode>, //
+    RpcImplementation, //
+    AutoCloseable {
 
     var NetconfClient client;
 
@@ -36,14 +44,17 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
     @Property
     var InstanceIdentifier path;
 
-    Registration<DataReader<InstanceIdentifier, CompositeNode>> operReaderReg
+    @Property
+    var ReconnectStrategy strategy;
 
+    Registration<DataReader<InstanceIdentifier, CompositeNode>> operReaderReg
     Registration<DataReader<InstanceIdentifier, CompositeNode>> confReaderReg
-
-    String name
-
+    Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> commitHandlerReg
+    
+    val String name
     MountProvisionService mountService
-
+    
+    
     public new(String name) {
         this.name = name;
         this.path = InstanceIdentifier.builder(INVENTORY_PATH).nodeWithKey(INVENTORY_NODE,
@@ -51,13 +62,14 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
     }
 
     def start(NetconfClientDispatcher dispatcher) {
-        client = new NetconfClient(name, socketAddress, dispatcher);
+        client = NetconfClient.clientFor(name, socketAddress, strategy, dispatcher);
         confReaderReg = mountInstance.registerConfigurationReader(path, this);
         operReaderReg = mountInstance.registerOperationalReader(path, this);
+        //commitHandlerReg = mountInstance.registerCommitHandler(path,this);
     }
 
     override readConfigurationData(InstanceIdentifier path) {
-        val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, path.toFilterStructure()));
+        val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, path.toFilterStructure()));
         val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
         return data?.findNode(path) as CompositeNode;
     }
@@ -133,6 +145,10 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
         return current;
     }
 
+    override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub")
+    }
+
     override close() {
         confReaderReg?.close()
         operReaderReg?.close()
index d23ec1cd61ae65ee507693638e03be9043b3e937..78f6d59f77ed2b2a7025b578d6090929ceead2dd 100644 (file)
@@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicInteger
 import org.w3c.dom.Document
 import org.w3c.dom.Element
 import org.opendaylight.controller.sal.common.util.Rpcs
+import java.util.List
+import com.google.common.collect.ImmutableList
 
 class NetconfMapping {
 
@@ -26,12 +28,18 @@ class NetconfMapping {
     public static val NETCONF_RPC_QNAME = new QName(NETCONF_QNAME,"rpc");
     public static val NETCONF_GET_QNAME = new QName(NETCONF_QNAME,"get");
     public static val NETCONF_GET_CONFIG_QNAME = new QName(NETCONF_QNAME,"get-config");
+    public static val NETCONF_SOURCE_QNAME = new QName(NETCONF_QNAME,"source");
+    public static val NETCONF_RUNNING_QNAME = new QName(NETCONF_QNAME,"running");
     public static val NETCONF_RPC_REPLY_QNAME = new QName(NETCONF_QNAME,"rpc-reply");
     public static val NETCONF_OK_QNAME = new QName(NETCONF_QNAME,"ok");
     public static val NETCONF_DATA_QNAME = new QName(NETCONF_QNAME,"data");
     
+     static List<Node<?>> RUNNING = Collections.<Node<?>>singletonList(new SimpleNodeTOImpl(NETCONF_RUNNING_QNAME,null,null));
+    public static val CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME,null,RUNNING);
 
     static val messageId = new AtomicInteger(0);
+    
+   
 
 
 
@@ -88,6 +96,15 @@ class NetconfMapping {
         }
     }
     
+        static def wrap(QName name,Node<?> additional,Node<?> node) {
+        if(node != null) {
+            return new CompositeNodeTOImpl(name,null,ImmutableList.of(additional,node));
+        }
+        else {
+            return new CompositeNodeTOImpl(name,null,ImmutableList.of(additional));
+        }
+    }
+    
     
     public static def Node<?> toCompositeNode(Document document) {
         return XmlDocumentUtils.toCompositeNode(document) as Node<?>
index c0de0d80a8c0f04fbb5a322c822acf4ca5e91661..4a077e663f187f6d23e05a771d4ec988290c8c90 100644 (file)
@@ -59,7 +59,6 @@ public class XmlMapper {
             throws UnsupportedDataTypeException {
         QName dataType = data.getNodeType();
         Element itemEl = doc.createElementNS(dataType.getNamespace().toString(), dataType.getLocalName());
-
         if (data instanceof SimpleNode<?>) {
             if (schema instanceof LeafListSchemaNode) {
                 writeValueOfNodeByType(itemEl, (SimpleNode<?>) data, ((LeafListSchemaNode) schema).getType());
@@ -73,11 +72,14 @@ public class XmlMapper {
             }
         } else { // CompositeNode
             for (Node<?> child : ((CompositeNode) data).getChildren()) {
-                DataSchemaNode childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
-                if (logger.isDebugEnabled()) {
-                    if (childSchema == null) {
-                        logger.debug("Probably the data node \"" + ((child == null) ? "" : child.getNodeType().getLocalName())
-                                + "\" is not conform to schema");
+                DataSchemaNode childSchema = null;
+                if(schema != null){
+                    childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
+                    if (logger.isDebugEnabled()) {
+                        if (childSchema == null) {
+                            logger.debug("Probably the data node \"" + ((child == null) ? "" : child.getNodeType().getLocalName())
+                                    + "\" is not conform to schema");
+                        }
                     }
                 }
                 itemEl.appendChild(translateToXmlAndReturnRootElement(doc, child, childSchema));
index d644cddff4855afe0a6e87b399a81d9eb5f5b152..95f526b2ecb535787570fd60fe97e96094421420 100644 (file)
@@ -67,6 +67,10 @@ public class NetconfClient implements Closeable {
         }
     }
 
+    public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
+        return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher);
+    }
+
     public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
             NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this(clientLabelForLogging, address,
index 221953e56e51053af95bc32bd866f2d51b99f05a..520627a09899c826f7a7254610cf8e9f7f776b65 100644 (file)
@@ -1,6 +1,7 @@
 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <capabilities>
         <capability>urn:ietf:params:netconf:base:1.0</capability>
+        <capability>urn:ietf:params:netconf:base:1.1</capability>
         <capability>urn:ietf:params:netconf:capability:exi:1.0</capability>
     </capabilities>
 </hello>
\ No newline at end of file
index 4e34591284e78e23e4b84f0553aea90c53792295..46f6f76412e01b8b09c45f209021fff8ec0d270d 100644 (file)
@@ -1,5 +1,6 @@
 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <capabilities>
         <capability>urn:ietf:params:netconf:base:1.0</capability>
+        <capability>urn:ietf:params:netconf:base:1.1</capability>
     </capabilities>
 </hello>