Added copyright and updated appropriate log levels
[vpnservice.git] / mdsalutil / mdsalutil-impl / src / main / java / org / opendaylight / vpnservice / mdsalutil / internal / MDSALManager.java
index 7a3ec91fa8f1eb2db55c143f7b3841686874530e..e31ad2d002d79af309a7eae048a3e51228c80a00 100644 (file)
@@ -1,30 +1,24 @@
 /*
- * Copyright (c) 2013 Ericsson AB.  All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
  */
 
 package org.opendaylight.vpnservice.mdsalutil.internal;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
 import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
 import org.opendaylight.vpnservice.mdsalutil.ActionType;
 import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
 import org.opendaylight.vpnservice.mdsalutil.GroupEntity;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
-import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
@@ -56,7 +50,7 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 
-public class MDSALManager implements IMdsalApiManager, AutoCloseable {
+public class MDSALManager implements AutoCloseable {
 
     private static final Logger s_logger = LoggerFactory.getLogger(MDSALManager.class);
 
@@ -64,10 +58,6 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
 
     private PacketProcessingService m_packetProcessingService;
 
-    private final AtomicInteger m_atomicInteger = new AtomicInteger();
-
-    //TODO : IF ID MANAGER IS RQD
-
     /**
      * Writes the flows and Groups to the MD SAL DataStore
      * which will be sent to the openflowplugin for installing flows/groups on the switch.
@@ -75,66 +65,40 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
      * uses this utility
      *
      * @param db - dataBroker reference
-     * @param PacketProcessingService for sending the packet outs
+     * @param pktProcService- PacketProcessingService for sending the packet outs
      */
     public MDSALManager(final DataBroker db, PacketProcessingService pktProcService) {
         m_dataBroker = db;
         m_packetProcessingService = pktProcService;
-
+        s_logger.info( "MDSAL Manager Initialized ") ;
     }
 
-
     @Override
     public void close() throws Exception {
         s_logger.info("MDSAL Manager Closed");
     }
 
-    @Override
-    public void printTest() {
-
-        s_logger.info(" INTER MODULECOMMUNICATION IS WORKING!!!!");
-    }
-    @Override
     public void installFlow(FlowEntity flowEntity) {
 
         try {
-            s_logger.info("within installFlow {}", flowEntity.getDpnId());
+            s_logger.trace("InstallFlow for flowEntity {} ", flowEntity);
 
             if (flowEntity.getCookie() == null) {
-              //  s_logger.info("Helium_sync: Cookie is null");
-                flowEntity.setCookie(new BigInteger("0110000", 16));
+               flowEntity.setCookie(new BigInteger("0110000", 16));
             }
 
             FlowKey flowKey = new FlowKey( new FlowId(flowEntity.getFlowId()) );
 
             FlowBuilder flowbld = flowEntity.getFlowBuilder();
 
-            Flow flow = flowbld.build() ;
-
             Node nodeDpn = buildDpnNode(flowEntity.getDpnId());
-            InstanceIdentifier<Node> nodeInstanceId = InstanceIdentifier.builder(Nodes.class)
-                    .child(Node.class, nodeDpn.getKey()).build();
-
             InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
                     .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
                     .child(Table.class, new TableKey(flowEntity.getTableId())).child(Flow.class,flowKey).build();
 
-            String sTransactionUri = generateTransactionUri();
-
-            TableKey tableKey = new TableKey(flowEntity.getTableId() );
-            InstanceIdentifier<Table> tableInstanceId = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeDpn.getKey())
-                    .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
-            Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
-
             WriteTransaction modification = m_dataBroker.newWriteOnlyTransaction();
 
-            //CHECK IF RQD
-           // modification.put(LogicalDatastoreType.CONFIGURATION, nodeInstanceId, nodeDpn, true);
-
-
-            modification.put(LogicalDatastoreType.CONFIGURATION, tableInstanceId, table);
-
-            modification.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flowbld.build());
+            modification.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flowbld.build(),true );
 
             CheckedFuture<Void,TransactionCommitFailedException> submitFuture  = modification.submit();
 
@@ -143,7 +107,7 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 @Override
                 public void onSuccess(final Void result) {
                     // Commited successfully
-                    s_logger.info( "Install Flow -- Committedsuccessfully ") ;
+                    s_logger.debug( "Install Flow -- Committedsuccessfully ") ;
                 }
 
                 @Override
@@ -160,27 +124,23 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 }
             });
         } catch (Exception e) {
-            s_logger.error("Could not install flow: {}, exception: {}", flowEntity, e.getMessage());
+            s_logger.error("Could not install flow: {}, exception: {}", flowEntity, e);
         }
     }
 
-    @Override
     public void installGroup(GroupEntity groupEntity) {
         try {
             Group group = groupEntity.getGroupBuilder().build();
 
             Node nodeDpn = buildDpnNode(groupEntity.getDpnId());
-            InstanceIdentifier<Node> nodeInstanceId = InstanceIdentifier.builder(Nodes.class)
-                    .child(Node.class, nodeDpn.getKey()).build();
+
             InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class)
                     .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
                     .child(Group.class, new GroupKey(new GroupId(groupEntity.getGroupId()))).build();
 
             WriteTransaction modification = m_dataBroker.newWriteOnlyTransaction();
 
-            //CHECK IF RQD
-         //   modification.put(LogicalDatastoreType.CONFIGURATION, nodeInstanceId, nodeDpn);
-            modification.put(LogicalDatastoreType.CONFIGURATION, groupInstanceId, group);
+            modification.put(LogicalDatastoreType.CONFIGURATION, groupInstanceId, group, true);
 
             CheckedFuture<Void,TransactionCommitFailedException> submitFuture  = modification.submit();
 
@@ -188,7 +148,7 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 @Override
                 public void onSuccess(final Void result) {
                     // Commited successfully
-                    s_logger.info( "Install Group -- Committedsuccessfully ") ;
+                    s_logger.debug( "Install Group -- Committedsuccessfully ") ;
                 }
 
                 @Override
@@ -205,12 +165,11 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 }
              });
            } catch (Exception e) {
-            s_logger.error("Could not install Group: {}, exception: {}", groupEntity, e.getMessage());
+            s_logger.error("Could not install Group: {}, exception: {}", groupEntity, e);
             throw e;
         }
     }
 
-    @Override
     public void removeFlow(FlowEntity flowEntity) {
         try {
             Node nodeDpn = buildDpnNode(flowEntity.getDpnId());
@@ -229,7 +188,7 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                     @Override
                     public void onSuccess(final Void result) {
                         // Commited successfully
-                        s_logger.info( "Delete Flow -- Committedsuccessfully ") ;
+                        s_logger.debug( "Delete Flow -- Committedsuccessfully ") ;
                     }
 
                     @Override
@@ -246,11 +205,10 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
 
                 });
         } catch (Exception e) {
-            s_logger.error("Could not remove Flow: {}, exception: {}", flowEntity, e.getMessage());
+            s_logger.error("Could not remove Flow: {}, exception: {}", flowEntity, e);
         }
     }
 
-    @Override
     public void removeGroup(GroupEntity groupEntity) {
         try {
             Node nodeDpn = buildDpnNode(groupEntity.getDpnId());
@@ -268,7 +226,7 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 @Override
                 public void onSuccess(final Void result) {
                     // Commited successfully
-                    s_logger.info( "Install Group -- Committedsuccessfully ") ;
+                    s_logger.debug( "Install Group -- Committedsuccessfully ") ;
                 }
 
                 @Override
@@ -284,32 +242,15 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
                 }
             });
         } catch (Exception e) {
-            s_logger.error("Could not remove Group: {}, exception: {}", groupEntity, e.getMessage());
+            s_logger.error("Could not remove Group: {}, exception: {}", groupEntity, e);
         }
     }
 
-    @Override
     public void modifyGroup(GroupEntity groupEntity) {
 
         installGroup(groupEntity);
     }
 
-    private String generateTransactionUri() {
-        long lTransactionIdOut = m_atomicInteger.incrementAndGet();
-
-        // TO DO Introduce this later
-      //  return "" + (lTransactionIdOut | m_lTransactionIdPrefix);
-        return "" + (lTransactionIdOut );
-    }
-/*
-    private String generateTransactionUriForFlow(long nTransactionId) {
-        long lTransactionIdOut = m_atomicInteger.incrementAndGet();
-        return Long.toString((lTransactionIdOut | m_lTransactionIdPrefix)) + EUtil.TRANSACTION_ID_SEPARATOR
-                + Long.toString(nTransactionId);
-    }
-*/
-
-    @Override
     public void sendPacketOut(long lDpnId, int groupId, byte[] payload) {
 
         List<ActionInfo> actionInfos = new ArrayList<ActionInfo>();
@@ -318,26 +259,17 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
         sendPacketOutWithActions(lDpnId, groupId, payload, actionInfos);
     }
 
-    @Override
     public void sendPacketOutWithActions(long lDpnId, long groupId, byte[] payload, List<ActionInfo> actionInfos) {
 
         m_packetProcessingService.transmitPacket(MDSALUtil.getPacketOut(actionInfos, payload, lDpnId,
                 getNodeConnRef("openflow:" + lDpnId, "0xfffffffd")));
     }
 
-    @Override
     public void sendARPPacketOutWithActions(long lDpnId, byte[] payload, List<ActionInfo> actions) {
-
         m_packetProcessingService.transmitPacket(MDSALUtil.getPacketOut(actions, payload, lDpnId,
                 getNodeConnRef("openflow:" + lDpnId, "0xfffffffd")));
     }
 
-    private NodeKey getNodeKey(long dpId) {
-        String nodeId = "openflow:" + dpId;
-        NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
-        return nodeKey;
-    }
-
     public InstanceIdentifier<Node> nodeToInstanceId(Node node) {
         return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
     }
@@ -361,11 +293,6 @@ public class MDSALManager implements IMdsalApiManager, AutoCloseable {
         return _nodeConnectorRef;
     }
 
-    private long getDpnIdFromNodeName(String nodeName) {
-        String dpId = nodeName.substring(nodeName.lastIndexOf(":") + 1);
-        return Long.parseLong(dpId);
-    }
-
     private Node buildDpnNode(long lDpnId) {
         NodeId nodeId = new NodeId("openflow:" + lDpnId);
         Node nodeDpn = new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();