Added built_in_flow_mods to dot and flowpaths 12/24112/1
authorCurt Beckmann <beckmann@brocade.com>
Tue, 14 Jul 2015 15:26:19 +0000 (17:26 +0200)
committerCurt Beckmann <beckmann@brocade.com>
Tue, 14 Jul 2015 15:26:19 +0000 (17:26 +0200)
Change-Id: Ia48f3a740618376c7c03218df35cd4aa744384bf
Signed-off-by: Curt Beckmann <beckmann@brocade.com>
parser/ofdpa-v2.0.0.2.odl-ttp.json
parser/src/main/java/org/opendaylight/ttp/parser/Main.java

index acc92d3c5ee022ecc4b1ef4c9911dea30a5438da..01fbd2bd8758788076a4f18efeb7c4c3166dd5a0 100644 (file)
       ]
     },
     {
-      "name": "Tunnel PCP Trust",
+      "name": "Tunnel DSCP Trust",
       "doc": [
         "Classify traffic class and color based on VLAN PCP field."
       ],
           "instruction_set": [
             {
               "instruction": "GOTO_TABLE",
-              "table": "MPLS L2  Port DSCP Trust"
+              "table": "MPLS L2 Port DSCP Trust"
             },
             {
               "instruction": "APPLY_ACTIONS",
           "instruction_set": [
             {
               "instruction": "GOTO_TABLE",
-              "table": "MPLS L2  Port DSCP Trust"
+              "table": "MPLS L2 Port DSCP Trust"
             },
             {
               "instruction": "APPLY_ACTIONS",
           "instruction_set": [
             {
               "instruction": "GOTO_TABLE",
-              "table": "MPLS L2  Port PCP Trust"
+              "table": "MPLS L2 Port PCP Trust"
             },
             {
               "instruction": "APPLY_ACTIONS",
                 },
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
             }
           ]
         }
-      ]
+      ],
+      "built_in_flow_mods": []
     },
     {
       "name": "MPLS L2 Port DSCP Trust",
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
           "instruction_set": [
             {
               "instruction": "GOTO_TABLE",
-              "table": "MPLS 2"
+              "table": "MPLS 3"
             },
             {
               "instruction": "APPLY_ACTIONS",
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
           "instruction_set": [
             {
               "instruction": "GOTO_TABLE",
-              "table": "MPLS 2"
+              "table": "MPLS 3"
             },
             {
               "instruction": "APPLY_ACTIONS",
               "zero_or_one": [
                 {
                   "instruction": "GOTO_TABLE",
-                  "table": "PolicyACL"
+                  "table": "Policy ACL"
                 }
               ]
             },
         "Actions based on packet color.",
         "Must be separate from L2 Policer table."
       ],
-      "flow_mod_types": []
+      "flow_mod_types": [],
+      "built_in_flow_mods": []
     },
     {
       "name": "Policy ACL",
       }
     ]
   }
-}
\ No newline at end of file
+}
index 30b79fa0a159b715f204fb5fde497c0b0f184610..d9f5c2806023eab006d64532028d9c882d64f3a6 100644 (file)
@@ -19,8 +19,11 @@ import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.flow_mod.properties.In
 import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.flow_mod.properties.instruction_set.ExactlyOne;
 import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.flow_mod.properties.instruction_set.ZeroOrOne;
 import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.opendaylight.ttps.table.type.patterns.TableTypePattern;
+import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.table.type.pattern.properties.NDMMetadata;
+import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.table.type.pattern.properties.NDMMetadataBuilder;
 import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.table.type.pattern.properties.FlowTables;
 import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.table.type.pattern.properties.flow_tables.FlowModTypes;
+import org.opendaylight.yang.gen.v1.urn.onf.ttp.rev140711.table.type.pattern.properties.flow_tables.BuiltInFlowMods;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
@@ -66,6 +69,7 @@ public class Main {
                 System.out.println("<cmd> validate <ttp-file>             // check the syntax of the ttp");
                 System.out.println("<cmd> compare <ttp-file1> <ttp-file2> // check 2 ttps for common flow paths");
                 System.out.println("<cmd> dot <ttp-file>                  // generate dot formatted table map graphic to stdout");
+                System.out.println("<cmd> flowpaths <ttp-file>            // generate list of flowpaths in ttp");
                 break;
             case "format":
             case "validate":
@@ -77,6 +81,15 @@ public class Main {
                     prettyPrintTTP(odlTTPs);
                 }
                 break;
+            case "flowpaths":
+                if (args.length != 2) {
+                    System.out.println("<cmd> "+args[0]+" <ttp-file>                    // check the syntax of the ttp");
+                }
+                else {
+                    OpendaylightTtps odlTTPs = readTTPFromFile(args[1]);
+                    printFlowPaths(odlTTPs.getTableTypePatterns().getTableTypePattern().get(0));
+                }
+                break;
             case "dot":
                 if (args.length != 2) {
                     System.out.println("<cmd> "+args[0]+" <ttp-file>                    // check the syntax of the ttp");
@@ -134,8 +147,9 @@ public class Main {
     }
 
     static void printDOT(TableTypePattern ttp) {
-        Map<String, String> legalTableHops = new HashMap<>();
+        Map<String, List<String>> legalTableHops = new HashMap<>();
         for (FlowTables flowTable : ttp.getFlowTables()) {
+            List<String> dests = new ArrayList<>();
             for (FlowModTypes fmt : flowTable.getFlowModTypes()) {// ft.getFlowModTypes()) {
                 for (InstructionSet ins : fmt.getInstructionSet()) {
 
@@ -161,18 +175,212 @@ public class Main {
                         }
                     }
 
+
                     // add a legal hop from the flow table to the action listed in the goto table
                     for (InstructionSetProperties gotoTable : gotoTables) {
-                        legalTableHops.put(flowTable.getName(), gotoTable.getTable());
+                        String dest = gotoTable.getTable();
+                        if (dests.contains(dest)) {
+                            System.out.println("dest already in list: " + dest);
+                        }
+                        else {
+                            System.out.println("adding goto_table to table dests " + flowTable.getName() + "," + gotoTable.getTable());
+                            dests.add(dest);
+                        }
+                        
                     }
                 }
             }
+            for (BuiltInFlowMods bifm : flowTable.getBuiltInFlowMods()) {// ft.getFlowModTypes()) {
+                for (InstructionSet ins : bifm.getInstructionSet()) {
+
+                    // get all the goto_table instructions even if they are in meta keywords
+                    List<InstructionSetProperties> gotoTables = new ArrayList<>();
+                    if (ins.getInstruction() != null) {
+                        if (ins.getInstruction().equalsIgnoreCase("goto_table")) {
+                            gotoTables.add(ins);
+                        }
+                    }
+                    if (ins.getExactlyOne() != null) {
+                        for (ExactlyOne eo : ins.getExactlyOne()) {
+                            if (eo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                gotoTables.add(eo);
+                            }
+                        }
+                    }
+                    if (ins.getZeroOrOne() != null) {
+                        for (ZeroOrOne zoo : ins.getZeroOrOne()) {
+                            if (zoo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                gotoTables.add(zoo);
+                            }
+                        }
+                    }
+
+                    // add a legal hop from the flow table to the action listed in the goto table
+                    for (InstructionSetProperties gotoTable : gotoTables) {
+                        String dest = gotoTable.getTable();
+                        if (dests.contains(dest)) {
+                            System.out.println("dest already in list: " + dest);
+                        }
+                        else {
+                            System.out.println("adding goto_table to table dests " + flowTable.getName() + "," + gotoTable.getTable());
+                            dests.add(dest);
+                        }
+                        
+                    }
+                }
+            }
+            if (!dests.isEmpty()) {
+                System.out.println("adding dest list to table hops " + flowTable.getName());
+
+                legalTableHops.put(flowTable.getName(), dests);
+            }
         }
         System.out.println("digraph ttp {");
-        for (Map.Entry<String, String> hop : legalTableHops.entrySet()) {
-            System.out.println("  \"" + hop.getKey() + "\" -> \"" + hop.getValue() + "\";");
+        for (String source : legalTableHops.keySet()) {
+            List<String> dests = legalTableHops.get(source);
+            for (String dest : dests) {
+                System.out.println("  \"" + source + "\" -> \"" + dest + "\";");
+            }
         }
         System.out.println("}");
     }
 
+    static void nextFlowPathHop(TableTypePattern ttp, String Path, String tableName, int recurse) {
+        boolean tableNameValid = false;
+
+        if (recurse > 12) {
+            System.out.println("excessive recursion, Path = " + Path);
+            return;
+        }
+        recurse++;
+        Path = Path.concat(tableName);
+//     System.out.println("nextFlowPathHop called, table= " + tableName + " recurse= " + recurse);
+        for (FlowTables flowTable : ttp.getFlowTables()) {
+            if (flowTable.getName().equals(tableName)) {
+                tableNameValid = true;
+                int fmtCount = 0;
+                List<String> dests = new ArrayList<>();
+                for (FlowModTypes fmt : flowTable.getFlowModTypes()) {
+                    boolean gotGoTo = false;
+                    if (fmtCount++ > 100) {
+                       System.out.println("more than 100 flowmodtypes in a table");
+                       break;
+                    }
+                    for (InstructionSet ins : fmt.getInstructionSet()) {
+                        if (ins.getInstruction() != null) {
+                           if (ins.getInstruction().equalsIgnoreCase("goto_table")) {
+                                gotGoTo = true;
+                               String destName = ins.getTable();
+                                if (!dests.contains(destName)) {
+                                    dests.add(destName);
+                                    nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                }
+                           }
+                       }
+                       if (ins.getExactlyOne() != null) {
+                           for (ExactlyOne eo : ins.getExactlyOne()) {
+                               if (eo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                    gotGoTo = true;
+                                   String destName = eo.getTable();
+                                    if (!dests.contains(destName)) {
+                                        dests.add(destName);
+                                        nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                    }
+                               }
+                           }
+                       }
+                       if (ins.getZeroOrOne() != null) {
+                           for (ZeroOrOne zoo : ins.getZeroOrOne()) {
+                               if (zoo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                    gotGoTo = true;
+                                   String destName = zoo.getTable();
+                                    if (!dests.contains(destName)) {
+                                        dests.add(destName);
+                                        nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                    }
+                               }
+                           }
+                       }
+
+                   }
+                    if (!gotGoTo) {
+                        if (!dests.contains("__NOGOTO__")) {
+                            dests.add("__NOGOTO__");
+                            System.out.println(Path);
+                        }
+                    }
+               }
+                if (fmtCount == 0) {
+                    System.out.println(Path + "[LAST TABLE has no FMTs!]");
+                }
+//                System.out.println("beginning BuiltIns for " + tableName);
+                for (BuiltInFlowMods bifm : flowTable.getBuiltInFlowMods()) {
+                    boolean gotGoTo = false;
+                    if (fmtCount++ > 100) {
+                       System.out.println("more than 100 flowmodtypes and builtins in a table");
+                       break;
+                    }
+                    for (InstructionSet ins : bifm.getInstructionSet()) {
+                        if (ins.getInstruction() != null) {
+                           if (ins.getInstruction().equalsIgnoreCase("goto_table")) {
+                                gotGoTo = true;
+                               String destName = ins.getTable();
+                                if (!dests.contains(destName)) {
+                                    dests.add(destName);
+                                    nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                }
+                           }
+                       }
+                       if (ins.getExactlyOne() != null) {
+                           for (ExactlyOne eo : ins.getExactlyOne()) {
+                               if (eo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                    gotGoTo = true;
+                                   String destName = eo.getTable();
+                                    if (!dests.contains(destName)) {
+                                        dests.add(destName);
+                                        nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                    }
+                               }
+                           }
+                       }
+                       if (ins.getZeroOrOne() != null) {
+                           for (ZeroOrOne zoo : ins.getZeroOrOne()) {
+                               if (zoo.getInstruction().equalsIgnoreCase("goto_table")) {
+                                    gotGoTo = true;
+                                   String destName = zoo.getTable();
+                                    if (!dests.contains(destName)) {
+                                        dests.add(destName);
+                                        nextFlowPathHop(ttp, Path.concat(" -> "), destName, recurse);
+                                    }
+                               }
+                           }
+                       }
+
+                   }
+                    if (!gotGoTo) {
+                        if (!dests.contains("__NOGOTO__")) {
+                            dests.add("__NOGOTO__");
+                            System.out.println(Path);
+                        }
+                    }
+               }
+           }
+        }
+        if (!tableNameValid) {
+            System.out.println(Path + " [LAST TABLE NOT FOUND!]");
+        }
+    }
+
+    static void printFlowPaths(TableTypePattern ttp) {
+        String Path = "";
+        System.out.println("Begin table names");
+        for (FlowTables ftLoop : ttp.getFlowTables()) {
+            System.out.println(ftLoop.getName());
+        }
+        System.out.println("End table names");
+        System.out.println("");
+        FlowTables flowTable = ttp.getFlowTables().get(0);
+        String tableName = flowTable.getName();
+        nextFlowPathHop(ttp, Path, tableName, 0);
+    }
 }