@@ -402,14 +402,13 @@ let string_of_action = make_string_of format_action
402
402
let string_of_seq = make_string_of format_seq
403
403
let string_of_par = make_string_of format_par
404
404
let string_of_flow = make_string_of format_flow
405
- let string_of_flowTable = make_string_of format_flowTable
406
405
407
406
let string_of_vlan (x : int ) : string =
408
407
Format. sprintf " Vlan = %d" x
409
-
408
+
410
409
let string_of_vlanpcp (x : dlVlanPcp ) : string =
411
410
Format. sprintf " VlanPcp = %d" x
412
-
411
+
413
412
let string_of_ethType (x : dlTyp ) : string =
414
413
let extra = if x = 0x800 then " (ip)"
415
414
else if x = 0x806 then " (arp)"
@@ -446,7 +445,7 @@ let string_of_tcpDstPort (x : tpPort) : string =
446
445
Format. sprintf " TCPDstPort = %d" x
447
446
448
447
let string_of_inPort (x : portId ) : string =
449
- Format. sprintf " In Port = %lu" x
448
+ Format. sprintf " InPort = %lu" x
450
449
451
450
let check (string_of : 'a -> string )
452
451
(x : 'a option )
@@ -473,52 +472,66 @@ let pattern_list (p : Pattern.t) : string list =
473
472
* contains the strings of the pattern and the second list contains
474
473
* the strings of the actions associated with the pattern. *)
475
474
let to_entry (f : flow ) : (string list) * (string list) =
476
- let open Core.Std.List in
475
+ let open Core.Std in
476
+ let open List in
477
477
let pattern_list = pattern_list f.pattern in
478
478
let action_list = map (concat (concat f.action)) string_of_action in
479
479
(pattern_list, action_list)
480
480
481
481
(* Pads a string with spaces so that it is atleast `len` characters. *)
482
482
let pad (len : int ) (e : string ) : string =
483
+ let open Core.Std in
483
484
let padding_size = max 0 (len - (String. length e)) in
484
485
let padding = String. make padding_size ' ' in
485
- Core.Std.String. concat [e; padding]
486
+ String. concat [e; padding]
487
+
488
+ (* Helper function *)
489
+ let unwrap x =
490
+ match x with
491
+ | None -> 0
492
+ | Some x -> x
486
493
487
494
(* Given a list of entries to be displayed in the table, calculate a pair
488
495
* containing the max characters in a pattern string and action string *)
489
- let table_size (sw_id : switchId ) (entries : ((string list) * (string list) ) list ) : int * int =
490
- let open Core.Std.List in
496
+ let table_size (label : string ) (entries : ((string list) * (string list) ) list ) : int * int =
497
+ let open Core.Std in
498
+ let open List in
491
499
let patterns = map entries fst |> concat in
492
500
let actions = map entries snd |> concat in
493
- let max_p = max_elt (map patterns String. length) (- ) |> Core.Std. uw in
494
- let max_a = max_elt (map actions String. length) (- ) |> Core.Std. uw in
495
- (max max_p ((Int64. to_string sw_id |> String. length) + 3 + (String. length " Pattern" )), max max_a (String. length " Action" ))
501
+ let max_p = max_elt (map patterns String. length) (- ) |> unwrap in
502
+ let max_a = max_elt (map actions String. length) (- ) |> unwrap in
503
+ (max max_p ((String. length label ) + 3 + (String. length " Pattern" )), max max_a (String. length " Action" ))
496
504
497
505
(* Create the top edge of the table *)
498
506
let top max_p max_a : string =
507
+ let open Core.Std in
499
508
let open Char in
500
509
let fill = String. make (max_p + max_a + 5 ) '-' in
501
510
Format. sprintf " +%s+\n " fill
502
511
503
512
(* Create the bottom edge of the table *)
504
513
let bottom max_p max_a : string =
514
+ let open Core.Std in
505
515
let fill = String. make (max_p + max_a + 5 ) '-' in
506
516
Format. sprintf " +%s+\n " fill
507
517
508
518
(* Create a divider between entries *)
509
519
let div max_p max_a : string =
520
+ let open Core.Std in
510
521
let fill = String. make (max_p + max_a + 5 ) '-' in
511
522
Format. sprintf " |%s|\n " fill
512
523
513
524
(* Create the columns of the table *)
514
- let title sw_id max_p max_a : string =
515
- let pattern = pad max_p (Format. sprintf " %Ld | Pattern" sw_id) in
525
+ let title label max_p max_a : string =
526
+ let open Core.Std in
527
+ let pattern = pad max_p (Format. sprintf " %s | Pattern" label) in
516
528
let action = pad max_a " Action" in
517
529
Format. sprintf " | %s | %s |\n " pattern action
518
530
519
531
(* Create a row in the table *)
520
532
let string_of_entry (max_p : int ) (max_a : int ) (e : (string list) * (string list) ) : string =
521
- let open Core.Std.List in
533
+ let open Core.Std in
534
+ let open List in
522
535
let padded_patterns = map (fst e) (pad max_p) in
523
536
let padded_actions = map (snd e) (pad max_a) in
524
537
let blank_action = String. make max_a ' ' in
@@ -539,14 +552,15 @@ let string_of_entry (max_p : int) (max_a : int) (e : (string list) * (string lis
539
552
helper ps rest acc'
540
553
in
541
554
helper padded_patterns padded_actions [(div max_p max_a)]
542
- |> rev |> Core.Std. String. concat
555
+ |> rev |> String. concat
543
556
544
- (* Given a switch id and a flowTable, returns an ascii flowtable *)
545
- let ascii_of_flowTable (sw_id : switchId ) (tbl : flowTable ) : string =
546
- let entries = Core.Std.List. map tbl to_entry in
547
- let (max_p, max_a) = table_size sw_id entries in
557
+ (* Given a label and a flowTable, returns an ascii flowtable *)
558
+ let string_of_flowTable ?(label =" " ) (tbl : flowTable ) : string =
559
+ let open Core.Std in
560
+ let entries = List. map tbl to_entry in
561
+ let (max_p, max_a) = table_size label entries in
548
562
let t = (top max_p max_a) in
549
- let l = (title sw_id max_p max_a) in
550
- let entry_strings = Core.Std. List. map entries (string_of_entry max_p max_a) in
563
+ let l = (title label max_p max_a) in
564
+ let entry_strings = List. map entries (string_of_entry max_p max_a) in
551
565
let b = bottom max_p max_a in
552
- Core.Std. String. concat (t :: l :: (Core.Std. List. append entry_strings [b]))
566
+ String. concat (t :: l :: (List. append entry_strings [b]))
0 commit comments