Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.
Open
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"
```
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
all: build

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bfcli main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pisc-cli main.go

clean:
rm bfcli
rm pisc-cli
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Protocol Independent Switch Control - Command Line Interface(PISC-CLI)

## Development envinment

- GVM(https://github.com/moovweb/gvm) 做 GO 版本管理
- GoLand 作為 IDE
- Golang version 1.14+
- Barefoot SDE version 9.2

## Function Overview
- completion : provide table name suggestion to user
- version : show version of PISC-CLI
- set-flow : insert entry into the table
- del-flow : delete entry/entries of the table
- table : list all the table name
- dump : print all entries of the table
- info : print table's information

## Run
PISC-CLI有Completion功能,補助使用者輸入Table名稱,因此執行方式有兩種。
1. 要使用completion功能,需要把PISC-CLI的路徑加到PATH裡頭
```
cd WHERE/IS/PISC-CLI
export PATH=$PATH:$PWD
```
再把PISC-CLI的Completion功能引進BASH
```
. <(pisc-cli completion)
```
就可以使用 tab key 所提供Command與Table Name的推薦(At now, dump, info support only)
```
pisc-cli [command] [flags] [arguments]
```
2. 若不想使用completion,直接執行PISC-CLI即可
```
./pisc-cli [command] [flags] [arguments]
```

## How to set a flow into device?
set-flow指令,因為table有三種不同的match方式,為了使用指令必須要按照規則,規則如下:
```
pisc-cli set-flow [TABLE NAME] [ACTION NAME] -m "match_key, ..." -a "action_value, ..."
```
且Match key和Action value的寫入順序必須要跟pipeline所設定的順序相同。


>設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 rib SwitchIngress.hit_route -m "10.0.0.1/24" -a "10"
```

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.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?
```
pisc-cli del-flow [TABLE_NAME] [Flag] [Arguments]
```
1. reset : clear all tables
```
pisc-cli del-flow -r
```
2. all : delete all entries of the table
```
// 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. 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] -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.
```
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]
```

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

2. show logo of PISC
```
pisc-cli version -l
```
27 changes: 1 addition & 26 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 Chun Ming Ou <breezestars@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand All @@ -27,22 +12,12 @@ var completionCmd = &cobra.Command{
Short: "Generates bash completion scripts",
Long: `To load completion run

. <(bfcli completion)`,
. <(pisc-cli completion)`,
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(os.Stdout)
},
}

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")
}
Loading