-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
93 lines (77 loc) · 1.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"context"
"fmt"
p4Config "github.com/antonjlin/p4-go/p4/config/v1"
p4 "github.com/antonjlin/p4-go/p4/v1"
"log"
"time"
)
func main() {
client := p4.GetClient("localhost:50001")
stream, sErr := client.StreamChannel(context.Background())
if sErr != nil {
fmt.Println(sErr)
log.Fatalf("cannot open stream channel with the server")
}
listener := p4.OpenStreamListener(stream)
p4.SetMastership(stream)
p4.SetPipelineConfigFromFile(client, "resources/p4info.p4")
p4.PrintTables(client)
table := p4Config.CreateTable()
table.AddPreamble(
p4Config.CreatePreamble(
33596298,
"FabricIngress.filtering.fwd_classifier",
"fwd_classifier",
),
)
table.AddMatchField(
p4Config.CreateMatchField(
1,
"ig_port",
nil,
9,
p4Config.MatchField_EXACT,
),
)
table.AddMatchField(
p4Config.CreateMatchField(
2,
"eth_dst",
nil,
48,
p4Config.MatchField_TERNARY,
),
)
table.AddMatchField(
p4Config.CreateMatchField(
3,
"eth_type",
nil,
16,
p4Config.MatchField_EXACT,
),
)
table.AddActionRef(
p4Config.CreateActionRef(
16840921,
p4Config.ActionRef_TABLE_AND_DEFAULT,
nil,
),
)
info := p4Config.P4Info{
Tables: []*p4Config.Table{
&table,
},
}
fmt.Printf("%+v\n", info)
p4.SetPipelineConfig(client, &info)
time.Sleep(1000 * time.Millisecond)
newConfig , err := p4.GetPipelineConfigs(client)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", newConfig)
listener.Wait()
}