BUG-4236: resolve TODOs - part 1
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / common / NodeStaticReplyTranslatorUtil.java
index 981072c725499b7a141f68d193d93ccd44c76a74..ffd687ec710a4dd9e0455cc2af96b400581d3df2 100644 (file)
@@ -16,9 +16,12 @@ import javax.annotation.CheckForNull;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
@@ -32,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectLiveness;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
@@ -52,18 +56,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
 
 /**
+ * <p>
  * openflowplugin-impl
  * org.opendaylight.openflowplugin.impl.common
  *
- *
- *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- *
- * Created: Mar 31, 2015
+ *         </p>
+ *         Created: Mar 31, 2015
  */
 public class NodeStaticReplyTranslatorUtil {
 
-    private NodeStaticReplyTranslatorUtil () {
+    private NodeStaticReplyTranslatorUtil() {
         throw new UnsupportedOperationException("Utility class");
     }
 
@@ -74,7 +77,7 @@ public class NodeStaticReplyTranslatorUtil {
      * @param reply
      * @return
      */
-    public static FlowCapableNode nodeDescTranslator(@CheckForNull final MultipartReplyDesc reply) {
+    public static FlowCapableNode nodeDescTranslator(@CheckForNull final MultipartReplyDesc reply, final IpAddress ipAddress) {
         Preconditions.checkArgument(reply != null);
         final FlowCapableNodeBuilder flowCapAugBuilder = new FlowCapableNodeBuilder();
         flowCapAugBuilder.setDescription(reply.getDpDesc());
@@ -82,6 +85,12 @@ public class NodeStaticReplyTranslatorUtil {
         flowCapAugBuilder.setManufacturer(reply.getMfrDesc());
         flowCapAugBuilder.setSoftware(reply.getSwDesc());
         flowCapAugBuilder.setSerialNumber(reply.getSerialNum());
+        flowCapAugBuilder.setTable(Collections.<Table>emptyList());
+        flowCapAugBuilder.setMeter(Collections.<Meter>emptyList());
+        flowCapAugBuilder.setGroup(Collections.<Group>emptyList());
+        if (ipAddress != null) {
+            flowCapAugBuilder.setIpAddress(ipAddress);
+        }
         return flowCapAugBuilder.build();
     }
 
@@ -111,15 +120,15 @@ public class NodeStaticReplyTranslatorUtil {
         if (reply.getCapabilities().isOFPMFBURST()) {
             mCapability.add(MeterBurst.class);
         }
-        if(reply.getCapabilities().isOFPMFKBPS()){
+        if (reply.getCapabilities().isOFPMFKBPS()) {
             mCapability.add(MeterKbps.class);
 
         }
-        if(reply.getCapabilities().isOFPMFPKTPS()){
+        if (reply.getCapabilities().isOFPMFPKTPS()) {
             mCapability.add(MeterPktps.class);
 
         }
-        if(reply.getCapabilities().isOFPMFSTATS()){
+        if (reply.getCapabilities().isOFPMFSTATS()) {
             mCapability.add(MeterStats.class);
 
         }
@@ -138,60 +147,55 @@ public class NodeStaticReplyTranslatorUtil {
         Preconditions.checkArgument(reply != null);
         final GroupFeaturesBuilder groupFeature = new GroupFeaturesBuilder();
         groupFeature.setMaxGroups(reply.getMaxGroups());
-        final List<Class<? extends GroupType>> supportedGroups =  new ArrayList<>();
-        if(reply.getTypes().isOFPGTALL()){
+        final List<Class<? extends GroupType>> supportedGroups = new ArrayList<>();
+        if (reply.getTypes().isOFPGTALL()) {
             supportedGroups.add(GroupAll.class);
         }
-        if(reply.getTypes().isOFPGTSELECT()){
+        if (reply.getTypes().isOFPGTSELECT()) {
             supportedGroups.add(GroupSelect.class);
         }
-        if(reply.getTypes().isOFPGTINDIRECT()){
+        if (reply.getTypes().isOFPGTINDIRECT()) {
             supportedGroups.add(GroupIndirect.class);
         }
-        if(reply.getTypes().isOFPGTFF()){
+        if (reply.getTypes().isOFPGTFF()) {
             supportedGroups.add(GroupFf.class);
         }
         groupFeature.setGroupTypesSupported(supportedGroups);
 
         final List<Class<? extends GroupCapability>> gCapability = new ArrayList<>();
-        if(reply.getCapabilities().isOFPGFCCHAINING()){
+        if (reply.getCapabilities().isOFPGFCCHAINING()) {
             gCapability.add(Chaining.class);
         }
-        if(reply.getCapabilities().isOFPGFCCHAININGCHECKS()){
+        if (reply.getCapabilities().isOFPGFCCHAININGCHECKS()) {
             gCapability.add(ChainingChecks.class);
         }
-        if(reply.getCapabilities().isOFPGFCSELECTLIVENESS()){
+        if (reply.getCapabilities().isOFPGFCSELECTLIVENESS()) {
             gCapability.add(SelectLiveness.class);
         }
-        if(reply.getCapabilities().isOFPGFCSELECTWEIGHT()){
+        if (reply.getCapabilities().isOFPGFCSELECTWEIGHT()) {
             gCapability.add(SelectWeight.class);
         }
         groupFeature.setGroupCapabilitiesSupported(gCapability);
-        /* TODO :
-         *  My recommendation would be, its good to have a respective model of
-         * 'type bits', which will generate a class where all these flags will eventually
-         * be stored as boolean. It will be convenient for application to check the
-         * supported action, rather then doing bitmap operation.
-         */
+
         final List<Long> supportActionByGroups = new ArrayList<>();
         for (final ActionType actionType : reply.getActionsBitmap()) {
             long supportActionBitmap = 0;
-            supportActionBitmap |= actionType.isOFPATOUTPUT()?(1 << 0): 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLOUT()?(1 << 11): 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLIN()?(1 << 12): 0;
-            supportActionBitmap |= actionType.isOFPATSETMPLSTTL()?(1 << 15): 0;
-            supportActionBitmap |= actionType.isOFPATDECMPLSTTL()?(1 << 16): 0;
-            supportActionBitmap |= actionType.isOFPATPUSHVLAN()?(1 << 17): 0;
-            supportActionBitmap |= actionType.isOFPATPOPVLAN()?(1 << 18): 0;
-            supportActionBitmap |= actionType.isOFPATPUSHMPLS()?(1 << 19): 0;
-            supportActionBitmap |= actionType.isOFPATPOPMPLS()?(1 << 20): 0;
-            supportActionBitmap |= actionType.isOFPATSETQUEUE()?(1 << 21): 0;
-            supportActionBitmap |= actionType.isOFPATGROUP()?(1 << 22): 0;
-            supportActionBitmap |= actionType.isOFPATSETNWTTL()?(1 << 23): 0;
-            supportActionBitmap |= actionType.isOFPATDECNWTTL()?(1 << 24): 0;
-            supportActionBitmap |= actionType.isOFPATSETFIELD()?(1 << 25): 0;
-            supportActionBitmap |= actionType.isOFPATPUSHPBB()?(1 << 26): 0;
-            supportActionBitmap |= actionType.isOFPATPOPPBB()?(1 << 27): 0;
+            supportActionBitmap |= actionType.isOFPATOUTPUT() ? (1 << 0) : 0;
+            supportActionBitmap |= actionType.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
+            supportActionBitmap |= actionType.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
+            supportActionBitmap |= actionType.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
+            supportActionBitmap |= actionType.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
+            supportActionBitmap |= actionType.isOFPATPUSHVLAN() ? (1 << 17) : 0;
+            supportActionBitmap |= actionType.isOFPATPOPVLAN() ? (1 << 18) : 0;
+            supportActionBitmap |= actionType.isOFPATPUSHMPLS() ? (1 << 19) : 0;
+            supportActionBitmap |= actionType.isOFPATPOPMPLS() ? (1 << 20) : 0;
+            supportActionBitmap |= actionType.isOFPATSETQUEUE() ? (1 << 21) : 0;
+            supportActionBitmap |= actionType.isOFPATGROUP() ? (1 << 22) : 0;
+            supportActionBitmap |= actionType.isOFPATSETNWTTL() ? (1 << 23) : 0;
+            supportActionBitmap |= actionType.isOFPATDECNWTTL() ? (1 << 24) : 0;
+            supportActionBitmap |= actionType.isOFPATSETFIELD() ? (1 << 25) : 0;
+            supportActionBitmap |= actionType.isOFPATPUSHPBB() ? (1 << 26) : 0;
+            supportActionBitmap |= actionType.isOFPATPOPPBB() ? (1 << 27) : 0;
             supportActionByGroups.add(Long.valueOf(supportActionBitmap));
         }
         groupFeature.setActions(supportActionByGroups);