@@ -18,21 +18,19 @@ package controller
1818import (
1919 "fmt"
2020
21- "github.com/Mellanox/spectrum-x-operator/pkg/config"
2221 "github.com/Mellanox/spectrum-x-operator/pkg/exec"
2322 libnetlink "github.com/Mellanox/spectrum-x-operator/pkg/lib/netlink"
2423)
2524
2625const (
27- railPeerIP = "rail_peer_ip"
28- railUplink = "rail_uplink"
26+ railPeerIP = "rail_peer_ip"
27+ railUplink = "rail_uplink"
28+ defaultPriority = 32768
2929)
3030
3131//go:generate ../../bin/mockgen -destination mock_flows.go -source flows.go -package controller
3232
3333type FlowsAPI interface {
34- DeleteBridgeDefaultFlows (bridge string ) error
35- AddHostRailFlows (bridge string , pf string , rail config.HostRail , infraRailSubnet string ) error
3634 AddPodRailFlows (cookie uint64 , vf , bridge , podIP , podMAC string ) error
3735 DeletePodRailFlows (cookie uint64 , bridge string ) error
3836}
@@ -44,68 +42,6 @@ type Flows struct {
4442 NetlinkLib libnetlink.NetlinkLib
4543}
4644
47- func (f * Flows ) DeleteBridgeDefaultFlows (bridge string ) error {
48- // delete normal action flows - creating a secured bridge is not supported with sriov-network-operator
49- // the error is ignored because in non secured bridge there are flows that cannot be deleted, specfically
50- // for cookie=0, the first time will work but second reconcile will fail.
51- // those are the default flows:
52- // cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x1 actions=controller(reason=)
53- // cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=2,recirc_id=0 actions=drop
54- // cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x3 actions=drop
55- // cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x2 actions=drop
56- // once the bridge is created as secured this code will be removed
57- _ , _ = f .Exec .Execute (fmt .Sprintf ("ovs-ofctl del-flows %s cookie=0x0/-1" , bridge ))
58-
59- return nil
60- }
61-
62- func (f * Flows ) AddHostRailFlows (bridge string , pf string , rail config.HostRail , infraRailSubnet string ) error {
63- link , err := f .NetlinkLib .LinkByName (bridge )
64- if err != nil {
65- return fmt .Errorf ("failed to get interface %s: %w" , bridge , err )
66- }
67- addrs , err := f .NetlinkLib .IPv4Addresses (link )
68- if err != nil {
69- return fmt .Errorf ("failed to get addresses for interface %s: %w" , bridge , err )
70- }
71-
72- // if we don't have all the addresses assigned we will have partial flows
73- // checking for 2 addresses because we don't have a proper api between the controllers
74- if len (addrs ) != 2 {
75- return fmt .Errorf ("expected 2 addresses for interface %s, got %s" , bridge , addrs )
76- }
77-
78- for _ , addr := range addrs {
79- flow := fmt .Sprintf (`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:local"` ,
80- bridge , defaultPriority , hostConfigCookie , addr .IP )
81- if _ , err := f .Exec .Execute (flow ); err != nil {
82- return fmt .Errorf ("failed to exec [%s]: %s" , flow , err )
83- }
84-
85- flow = fmt .Sprintf (`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,ip,nw_dst=%s,actions=output:local"` ,
86- bridge , defaultPriority , hostConfigCookie , addr .IP )
87- if _ , err := f .Exec .Execute (flow ); err != nil {
88- return fmt .Errorf ("failed to exec [%s]: %s" , flow , err )
89- }
90- }
91-
92- // TOR is the gateway for the outer ip
93- flow := fmt .Sprintf (`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:%s"` ,
94- bridge , defaultPriority , hostConfigCookie , rail .PeerLeafPortIP , pf )
95- if _ , err := f .Exec .Execute (flow ); err != nil {
96- return fmt .Errorf ("failed to exec [%s]: %s" , flow , err )
97- }
98-
99- flow = fmt .Sprintf (`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,` +
100- `ip,in_port=local,nw_dst=%s,actions=output:%s"` ,
101- bridge , defaultPriority , hostConfigCookie , infraRailSubnet , pf )
102- if _ , err := f .Exec .Execute (flow ); err != nil {
103- return fmt .Errorf ("failed to exec [%s]: %s" , flow , err )
104- }
105-
106- return nil
107- }
108-
10945func (f * Flows ) AddPodRailFlows (cookie uint64 , vf , bridge , podIP , podMAC string ) error {
11046 // ovs-ofctl add-flow -OOpenFlow13 $RAIL_BR "table=0, arp,arp_tpa=${CONTAINER_IP} actions=output:${REP_PORT}"
11147 flow := fmt .Sprintf (`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:%s"` ,
0 commit comments