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

k8snetworkplumbingwg / sriov-network-operator / 10058808149

23 Jul 2024 12:22PM UTC coverage: 43.964% (+0.6%) from 43.351%
10058808149

Pull #659

github

web-flow
Merge f199eb95f into 588abb449
Pull Request #659: Configure IB VFs' GUIDs using a statically provided GUID pool

212 of 280 new or added lines in 13 files covered. (75.71%)

2 existing lines in 1 file now uncovered.

6526 of 14844 relevant lines covered (43.96%)

0.48 hits per line

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

94.12
/pkg/host/internal/infiniband/guid.go
1
package infiniband
2

3
import (
4
        "fmt"
5
        "math/rand"
6
        "net"
7
)
8

9
// GUID address is an uint64 encapsulation for network hardware address
10
type GUID uint64
11

12
const (
13
        guidLength = 8
14
        byteBitLen = 8
15
        byteMask   = 0xff
16
)
17

18
// ParseGUID parses string only as GUID 64 bit
19
func ParseGUID(s string) (GUID, error) {
1✔
20
        ha, err := net.ParseMAC(s)
1✔
21
        if err != nil {
2✔
22
                return 0, err
1✔
23
        }
1✔
24
        if len(ha) != guidLength {
1✔
NEW
25
                return 0, fmt.Errorf("invalid GUID address %s", s)
×
NEW
26
        }
×
27
        var guid uint64
1✔
28
        for idx, octet := range ha {
2✔
29
                guid |= uint64(octet) << uint(byteBitLen*(guidLength-1-idx))
1✔
30
        }
1✔
31
        return GUID(guid), nil
1✔
32
}
33

34
// String returns the string representation of GUID
35
func (g GUID) String() string {
1✔
36
        return g.HardwareAddr().String()
1✔
37
}
1✔
38

39
// HardwareAddr returns GUID representation as net.HardwareAddr
40
func (g GUID) HardwareAddr() net.HardwareAddr {
1✔
41
        value := uint64(g)
1✔
42
        ha := make(net.HardwareAddr, guidLength)
1✔
43
        for idx := guidLength - 1; idx >= 0; idx-- {
2✔
44
                ha[idx] = byte(value & byteMask)
1✔
45
                value >>= byteBitLen
1✔
46
        }
1✔
47

48
        return ha
1✔
49
}
50

51
func generateRandomGUID() net.HardwareAddr {
1✔
52
        guid := make(net.HardwareAddr, 8)
1✔
53

1✔
54
        // First field is 0x01 - xfe to avoid all zero and all F invalid guids
1✔
55
        guid[0] = byte(1 + rand.Intn(0xfe))
1✔
56

1✔
57
        for i := 1; i < len(guid); i++ {
2✔
58
                guid[i] = byte(rand.Intn(0x100))
1✔
59
        }
1✔
60

61
        return guid
1✔
62
}
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

© 2025 Coveralls, Inc