Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Flow_cheatsheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@


```bash
pisc-cli set-flow pipe.SwitchIngress.rmac SwitchIngress.rmac_hit -m "ff:ff:ff:ff:ff:ff" -a ""
pisc-cli set-flow pipe.SwitchIngress.dmac SwitchIngress.dmac_hit -m "ff:ff:ff:ff:ff:ff" -a "511"
pisc-cli set-flow pipe.SwitchIngress.fib SwitchIngress.hit_route_port -m "255.255.255.255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib_24 SwitchIngress.hit_route_port -m "255.255.255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib_20 SwitchIngress.hit_route_port -m "15.255.255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib_16 SwitchIngress.hit_route_port -m "255.255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib_12 SwitchIngress.hit_route_port -m "15.255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib_8 SwitchIngress.hit_route_port -m "255" -a "511"
pisc-cli set-flow pipe.SwitchIngress.rib SwitchIngress.hit_route_port -m "255.255.255.255/255.255.255.255, 4000" -a "511"
pisc-cli set-flow pipe.SwitchIngress.nexthop SwitchIngress.set_nexthop -m "255" -a "511, ff:ff:ff:ff:ff:ff"
pisc-cli set-flow pipe.SwitchEgress.smac_rewrite_by_portid SwitchEgress.rewrite_smac -m "511/511, 4000" -a "ff:ff:ff:ff:ff:ff"
pisc-cli set-flow pipe.SwitchIngress.arp SwitchIngress.arp_response -m "511/511, 0xffff, 0xffff, 255.255.255.255/255.255.255.255, 4000" -a "ff:ff:ff:ff:ff:ff"
pisc-cli set-flow pipe.SwitchIngress.acl SwitchIngress.output -m "511/511, 0xffff/0xffff, aa:aa:aa:aa:aa:aa/ff:ff:ff:ff:ff:ff, 255.255.255.255/255.255.255.255, 255.255.255.255/255.255.255.255, 255/255, 4000" -a "10"
pisc-cli set-flow pipe.SwitchIngress.smac SwitchIngress.smac_hit -m "ff:ff:ff:ff:ff:ff" -a "511" -t 600

pisc-cli set-flow rmac SwitchIngress.rmac_hit -m "ff:ff:ff:ff:ff:ff" -a ""
pisc-cli set-flow dmac SwitchIngress.dmac_hit -m "ff:ff:ff:ff:ff:ff" -a "511"
pisc-cli set-flow fib SwitchIngress.hit_route_port -m "255.255.255.255" -a "511"
pisc-cli set-flow rib_24 SwitchIngress.hit_route_port -m "255.255.255" -a "511"
pisc-cli set-flow rib_20 SwitchIngress.hit_route_port -m "15.255.255" -a "511"
pisc-cli set-flow rib_16 SwitchIngress.hit_route_port -m "255.255" -a "511"
pisc-cli set-flow rib_12 SwitchIngress.hit_route_port -m "15.255" -a "511"
pisc-cli set-flow rib_8 SwitchIngress.hit_route_port -m "255" -a "511"
pisc-cli set-flow rib SwitchIngress.hit_route_port -m "255.255.255.255/255.255.255.255, 4000" -a "511"
pisc-cli set-flow nexthop SwitchIngress.set_nexthop -m "255" -a "511, ff:ff:ff:ff:ff:ff"
pisc-cli set-flow smac_rewrite_by_portid SwitchEgress.rewrite_smac -m "511/511, 4000" -a "ff:ff:ff:ff:ff:ff"
pisc-cli set-flow arp SwitchIngress.arp_response -m "511/511, 0xffff, 0xffff, 255.255.255.255/255.255.255.255, 4000" -a "ff:ff:ff:ff:ff:ff"
pisc-cli set-flow acl SwitchIngress.output -m "511/511, 0xffff/0xffff, aa:aa:aa:aa:aa:aa/ff:ff:ff:ff:ff:ff, 255.255.255.255/255.255.255.255, 255.255.255.255/255.255.255.255, 255/255, 4000" -a "10"
pisc-cli set-flow smac SwitchIngress.smac_hit -m "ff:ff:ff:ff:ff:ff" -a "511" -t 60000

```


```bash
pisc-cli del-flow pipe.SwitchIngress.rmac -m "ff:ff:ff:ff:ff:ff"
pisc-cli del-flow pipe.SwitchIngress.dmac -m "ff:ff:ff:ff:ff:ff"
pisc-cli del-flow pipe.SwitchIngress.fib -m "255.255.255.255"
pisc-cli del-flow pipe.SwitchIngress.rib_24 -m "255.255.255"
pisc-cli del-flow pipe.SwitchIngress.rib_20 -m "15.255.255"
pisc-cli del-flow pipe.SwitchIngress.rib_16 -m "255.255"
pisc-cli del-flow pipe.SwitchIngress.rib_12 -m "15.255"
pisc-cli del-flow pipe.SwitchIngress.rib_8 -m "255"
pisc-cli del-flow pipe.SwitchIngress.rib -m "255.255.255.255/255.255.255.255, 4000"
pisc-cli del-flow pipe.SwitchIngress.nexthop -m "255"
pisc-cli del-flow pipe.SwitchEgress.smac_rewrite_by_portid -m "511/511, 4000"
pisc-cli del-flow pipe.SwitchIngress.arp -m "511/511, 0xffff, 0xffff, 255.255.255.255/255.255.255.255, 4000"
pisc-cli del-flow pipe.SwitchIngress.acl -m "511/511, 0xffff/0xffff, aa:aa:aa:aa:aa:aa/ff:ff:ff:ff:ff:ff, 255.255.255.255/255.255.255.255, 255.255.255.255/255.255.255.255, 255/255, 4000"
pisc-cli del-flow pipe.SwitchIngress.smac -m "ff:ff:ff:ff:ff:ff"

pisc-cli del-flow rmac -m "ff:ff:ff:ff:ff:ff"
pisc-cli del-flow dmac -m "ff:ff:ff:ff:ff:ff"
pisc-cli del-flow fib -m "255.255.255.255"
pisc-cli del-flow rib_24 -m "255.255.255"
pisc-cli del-flow rib_20 -m "15.255.255"
pisc-cli del-flow rib_16 -m "255.255"
pisc-cli del-flow rib_12 -m "15.255"
pisc-cli del-flow rib_8 -m "255"
pisc-cli del-flow rib -m "255.255.255.255/255.255.255.255, 4000"
pisc-cli del-flow nexthop -m "255"
pisc-cli del-flow smac_rewrite_by_portid -m "511/511, 4000"
pisc-cli del-flow arp -m "511/511, 0xffff, 0xffff, 255.255.255.255/255.255.255.255, 4000"
pisc-cli del-flow acl -m "511/511, 0xffff/0xffff, aa:aa:aa:aa:aa:aa/ff:ff:ff:ff:ff:ff, 255.255.255.255/255.255.255.255, 255.255.255.255/255.255.255.255, 255/255, 4000"
pisc-cli del-flow smac -m "ff:ff:ff:ff:ff:ff"
```
86 changes: 51 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,35 @@ pisc-cli set-flow [TABLE NAME] [ACTION NAME] -m "match_key, ..." -a "action_valu
且Match key和Action value的寫入順序必須要跟pipeline所設定的順序相同。


1. Exact : smac table example
>設table key的時候請務必確認,你所設定的值是否跟table所需要的值是一致的,假如說table需要MAC Addr,但卻你下的指令是沒有格式的數字或IP, 這樣會直接設下去,且會產生問題。

1. Exact : smac table example.
```
pisc-cli set-flow pipe.SwitchIngress.smac SwitchIngress.smac_hit -m "aa:aa:aa:aa:aa:aa" -a "10"
```

2. LPM : rib table example。對於LPM, 必須要按照CIDR的形式輸入,否則會出現error.
```
pisc-cli set-flow pipe.SwitchIngress.rib SwitchIngress.hit_route -m "10.0.0.1/24" -a "10"
pisc-cli set-flow pipe.SwitchIngress.rib SwitchIngress.hit_route -m "10.0.0.1/24" -a "10"
pisc-cli set-flow rib SwitchIngress.hit_route -m "10.0.0.1/24" -a "10"
```

3. Ternary : acl example。對於Ternary,value與mask的長度以及形式必須要相同。
3. Ternary : acl example。對於Ternary,value與mask的長度以及形式必須要相同。Ternary match key的區分僅能靠Match key的priority的欄位。PISC-CLI利用 match flag來題共設定priority。priority的設置方式與其他match key相同,且順序也是位於match的最後面。

```
pisc-cli set-flow pipe.SwitchIngress.acl SwitchIngress.output -m "10/10, 0x0800/0xffff, fa:aa:aa:aa:aa:fa/ff:ff:ff:ff:ff:ff, 127.0.0.1/255.255.255.255, 11.1.1.2/255.255.255.255" -a "0"
pisc-cli set-flow pipe.SwitchIngress.arp SwitchIngress.arp_response -m "511/511, 0xffff, ffff, 255.255.255.255/255.255.255.255, 4000(priority value)" -a "ff:ff:ff:ff:ff:ff" pisc-cli set-flow acl SwitchIngress.output -m "10/10, 0x0800/0xffff, fa:aa:aa:aa:aa:fa/ff:ff:ff:ff:ff:ff, 127.0.0.1/255.255.255.255, 11.1.1.2/255.255.255.255" -a "0"
```

## TTL - table TIMEOUT value setup
SMAC table has an idle_timeout function. This function will send a notification to the controller to notify that the entry's life has expired and need to remove it.
In PISC-CLI, it delivers TTL setting by -t flag on set-flow function.
The scale of the flag is milliseconds. min, max value of the TTL need to refer PISC.

Example as following:

```
pisc-cli set-flow pipe.SwitchIngress.smac SwitchIngress.smac_hit -m "ff:ff:ff:ff:ff:ff" -a "511" -t 60000
pisc-cli set-flow smac SwitchIngress.smac_hit -m "ff:ff:ff:ff:ff:ff" -a "511" -t 60000
```

## How to delete entry/entries from device?
Expand All @@ -73,49 +88,50 @@ pisc-cli del-flow [TABLE_NAME] [Flag] [Arguments]
// Do not confuse with set-flow's "-a" flag. It's totally diffrent.
pisc-cli del-flow [TABLE_NAME] -a
pisc-cli del-flow pipe.SwitchIngress.fib -a
pisc-cli del-flow fib -a
```
3. entry : delete specific entry/entries number
3. match : delete specific entry by match keys.
the match flag acts like set-flow function.
the match flag need to specify table's match keys to delete entry.
```
pisc-cli del-flow [TABLE_NAME] -e "entry_number, ..."
```
```
// Assume that we have four entries{0, 1, ,2 ,3} in rib table.
// Also, we can use "info" command to see the entry number.
// About deleting entry, we don't need to care about the order of entry number.

pisc-cli del-flow pipe.SwitchIngress.rib -e "1, 0, 2"

// After deleting, the entry number will change to another.
// Please check the entry number everytime after deleting.

pisc-cli del-flow pipe.SwitchIngress.rib -e "3" - error
pisc-cli del-flow [TABLE_NAME] -m "Match key, ..."
pisc-cli del-flow pipe.SwitchIngress.rib -m "192.168.1.7/255.255.255.255, 4000"
pisc-cli del-flow rib -m "192.168.1.7/255.255.255.255, 4000"
```

## How to show the table and entries information?
```
pisc-cli [command] [TABLE_NAME]
```
1. table : list all table name.
```
pisc-cli table
```
2. dump : dump all entries of the table, also -a flag will dump all tables.
```
pisc-cli dump
pisc-cli dump -a
```
```
pisc-cli table
```
2. dump : dump all entries of the table.
```
pisc-cli dump [TABLE_NAME]
pisc-cli dump pipe.SwitchIngress.fib or pisc-cli dump fib
```
```
// dump all tables entries
pisc-cli dump -a
// dump all entries counts of the table.
pisc-cli dump -c
// also can dump all tables entries counts.
pisc-cli dump -a -c
```
3. info : show table information to the user
```
pisc-cli info [TALBE_NAME]
```
```
pisc-cli info [TALBE_NAME]
```

## Show version and logo
1. show version
```
pisc-cli version
```
```
pisc-cli version
```

2. show logo of PISC
```
pisc-cli version -l
```
```
pisc-cli version -l
```
10 changes: 0 additions & 10 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ var completionCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(completionCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// completionCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// completionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
143 changes: 123 additions & 20 deletions cmd/delFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,138 @@ package cmd

import (
"fmt"

"github.com/P4Networking/pisc/util"
"github.com/P4Networking/pisc/util/enums/id"
"github.com/P4Networking/proto/go/p4"
"github.com/spf13/cobra"
"io"
"log"
"strings"
)

var (
reset bool
delEntry []string
)

// delFlowCmd represents the delFlow command
var delFlowCmd = &cobra.Command{
Use: "del-flow",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Use: "del-flow TABLE-NAME ",
Short: "Delete entries from table",
Long: `del-flow can remove all of the entries from specific table`,
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_, _, conn, cancel, p4Info, _ := initConfigClient()
defer conn.Close()
defer cancel()
var argsList []string
for _, v := range p4Info.Tables {
if strings.Contains(v.Name, preFixIg) || strings.Contains(v.Name, preFixEg) {
strs := strings.Split(v.Name, ".")
if toComplete == "" || strings.Contains(toComplete, "pipe") {
argsList = append(argsList, v.Name)
} else {
argsList = append(argsList, strs[2])
}
}
}
return argsList, cobra.ShellCompDirectiveNoFileComp
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("delFlow called")

if (all || len(delEntry) > 0) && len(args) <= 0 {
cmd.Help()
return
}
for a, v := range delEntry {
delEntry[a] = strings.Replace(v, " ", "", -1)
}

cliAddr, ctxAddr, conn, cancel, p4Info, _ := initConfigClient()
defer conn.Close()
defer cancel()
cli := *cliAddr
ctx := *ctxAddr

if !reset {
argsList, _ := p4Info.GuessTableName(args[0])
if len(argsList) != 1 {
for _, v := range argsList {
strs := strings.Split(v, ".")
if strings.EqualFold(strs[2], args[0]) {
args[0] = v
}
}
} else {
args[0] = argsList[0]
}
}

for _, v := range p4Info.Tables {
if strings.HasPrefix(v.Name, preFixIg) || strings.HasPrefix(v.Name, preFixEg) {
if (all || len(delEntry) > 0) && v.Name != args[0] {
continue
}
stream, err := cli.Read(ctx, genReadRequestWithId(v.ID))
if err != nil {
log.Fatalf("Got error, %v \n", err.Error())
return
}

for {
rsp, err := stream.Recv()
if err == io.EOF {
break
}
if rsp != nil {
if len(rsp.GetEntities()) == 0 {
fmt.Printf("%s table is empty\n", v.Name)
break
}
var cnt []int
var err error

if all || reset {
cnt, err = DeleteEntries(&rsp, &cli, &ctx)
if err != nil {
fmt.Printf("Failed to delete entry: table \"%s\" with fields: %s\n", v.Name, rsp.Entities[cnt[0]].GetTableEntry().Key.Fields)
} else {
fmt.Printf("%d entires of \"%s\" table have cleared\n", len(cnt), v.Name)
}
} else if len(delEntry) > 0 {
table, _ := p4Info.GetTableById(id.TableId(v.ID))
collectedMatchTypes, ok := collectTableMatchTypes(table, &delEntry)
if !ok {
fmt.Println("Match keys are not matched")
return
}
fmt.Print("Make Match Key... ")
if match := BuildMatchKeys(&collectedMatchTypes); match != nil {
delReq := util.GenWriteRequestWithId(p4.Update_DELETE, id.TableId(v.ID), match, nil)
fmt.Print("Write Delete Reqeust... ")
_, err := cli.Write(ctx, delReq)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("DONE.")
} else {
fmt.Println("Please Check match keys and inputted arguments.")
}
}
}
}
}
}
if reset {
fmt.Println("Reset complete.")
}
},
}

func init() {
rootCmd.AddCommand(delFlowCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// delFlowCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// delFlowCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
delFlowCmd.Flags().BoolVarP(&all, "all", "a", false, "delete all entries of the table")
delFlowCmd.Flags().BoolVarP(&reset, "reset", "r", false, "clear all of the tables")
delFlowCmd.Flags().StringSliceVarP(&delEntry, "match", "m", []string{}, "delete specific entry by given entry number")
}
Loading