• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 20688122676

04 Jan 2026 05:18AM UTC coverage: 22.584% (-0.03%) from 22.616%
20688122676

push

github

web-flow
Add open flow sync refer to ovn-k8s (#6117)

* add openflow sync refer to ovn-k8s

Signed-off-by: clyi <clyi@alauda.io>

0 of 180 new or added lines in 5 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

12067 of 53432 relevant lines covered (22.58%)

0.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/daemon/flow_rules_linux.go
1
package daemon
2

3
import (
4
        "errors"
5
        "fmt"
6
        "strings"
7

8
        "k8s.io/klog/v2"
9

10
        kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
11
        "github.com/kubeovn/kube-ovn/pkg/util"
12
)
13

14
const flowKindUnderlayService = "usvc"
15

NEW
16
func (c *Controller) AddOrUpdateUnderlaySubnetSvcLocalFlowCache(serviceIP string, port uint16, protocol, dstMac, underlayNic, bridgeName string) error {
×
NEW
17
        inPort, err := c.getPortID(bridgeName, underlayNic)
×
NEW
18
        if err != nil {
×
NEW
19
                return err
×
NEW
20
        }
×
21

NEW
22
        outPort, err := c.getPortID(bridgeName, "patch-localnet.")
×
NEW
23
        if err != nil {
×
NEW
24
                return err
×
NEW
25
        }
×
26

NEW
27
        isIPv6 := util.CheckProtocol(serviceIP) == kubeovnv1.ProtocolIPv6
×
NEW
28
        protoStr := ""
×
NEW
29
        switch strings.ToUpper(protocol) {
×
NEW
30
        case "TCP":
×
NEW
31
                protoStr = "tcp"
×
NEW
32
                if isIPv6 {
×
NEW
33
                        protoStr = "tcp6"
×
NEW
34
                }
×
NEW
35
        case "UDP":
×
NEW
36
                protoStr = "udp"
×
NEW
37
                if isIPv6 {
×
NEW
38
                        protoStr = "udp6"
×
NEW
39
                }
×
NEW
40
        default:
×
NEW
41
                return fmt.Errorf("unsupported protocol %s", protocol)
×
42
        }
43

NEW
44
        cookie := fmt.Sprintf("0x%x", util.UnderlaySvcLocalOpenFlowCookieV4)
×
NEW
45
        nwDst := "nw_dst"
×
NEW
46
        if isIPv6 {
×
NEW
47
                cookie = fmt.Sprintf("0x%x", util.UnderlaySvcLocalOpenFlowCookieV6)
×
NEW
48
                nwDst = "ipv6_dst"
×
NEW
49
        }
×
50

NEW
51
        flow := fmt.Sprintf("cookie=%s,priority=%d,in_port=%d,%s,%s=%s,tp_dst=%d "+
×
NEW
52
                "actions=mod_dl_dst:%s,output:%d",
×
NEW
53
                cookie, util.UnderlaySvcLocalOpenFlowPriority, inPort, protoStr, nwDst, serviceIP, port, dstMac, outPort)
×
NEW
54

×
NEW
55
        key := buildFlowKey(flowKindUnderlayService, serviceIP, port, protocol, "")
×
NEW
56
        c.setFlowCache(c.flowCache, bridgeName, key, []string{flow})
×
NEW
57

×
NEW
58
        klog.V(5).Infof("updated underlay flow cache for service %s", key)
×
NEW
59
        c.requestFlowSync()
×
NEW
60
        return nil
×
61
}
62

NEW
63
func (c *Controller) deleteUnderlaySubnetSvcLocalFlowCache(bridgeName, serviceIP string, port uint16, protocol string) {
×
NEW
64
        key := buildFlowKey(flowKindUnderlayService, serviceIP, port, protocol, "")
×
NEW
65

×
NEW
66
        c.deleteFlowCache(c.flowCache, bridgeName, key)
×
NEW
67

×
NEW
68
        klog.V(5).Infof("deleted underlay flow cache for service %s", key)
×
NEW
69
        c.requestFlowSync()
×
NEW
70
}
×
71

NEW
72
func buildFlowKey(kind, ip string, port uint16, protocol, extra string) string {
×
NEW
73
        if extra == "" {
×
NEW
74
                return fmt.Sprintf("%s-%s-%s-%d", kind, ip, protocol, port)
×
NEW
75
        }
×
NEW
76
        return fmt.Sprintf("%s-%s-%s-%d-%s", kind, ip, protocol, port, extra)
×
77
}
78

NEW
79
func (c *Controller) getPortID(bridgeName, portName string) (int, error) {
×
NEW
80
        if c.ovsClient == nil {
×
NEW
81
                return 0, errors.New("ovs client not initialized")
×
NEW
82
        }
×
83

NEW
84
        portInfo, err := c.ovsClient.OpenFlow.DumpPort(bridgeName, portName)
×
NEW
85
        if err != nil {
×
NEW
86
                return 0, fmt.Errorf("failed to dump port %s on bridge %s: %w", portName, bridgeName, err)
×
NEW
87
        }
×
NEW
88
        return portInfo.PortID, nil
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc