(nlri bgp.NLRI)
| 36 | ) |
| 37 | |
| 38 | func addrPrefixOnlySerialize(nlri bgp.NLRI) []byte { |
| 39 | switch T := nlri.(type) { |
| 40 | case *bgp.IPAddrPrefix: |
| 41 | byteLen := T.Prefix.Addr().BitLen() / 8 |
| 42 | b := make([]byte, byteLen+1) |
| 43 | copy(b, T.Prefix.Addr().AsSlice()) |
| 44 | b[byteLen] = uint8(T.Prefix.Bits()) |
| 45 | return b |
| 46 | case *bgp.LabeledVPNIPAddrPrefix: |
| 47 | byteLen := T.Prefix.Addr().BitLen() / 8 |
| 48 | // RD and length |
| 49 | b := make([]byte, byteLen+9) |
| 50 | serializedRD, _ := T.RD.Serialize() |
| 51 | copy(b, serializedRD) |
| 52 | copy(b[8:], T.Prefix.Addr().AsSlice()) |
| 53 | b[8+byteLen] = uint8(T.Prefix.Bits()) |
| 54 | return b |
| 55 | } |
| 56 | return []byte(nlri.String()) |
| 57 | } |
| 58 | |
| 59 | func AddrPrefixOnlyCompare(a, b bgp.NLRI) int { |
| 60 | return bytes.Compare(addrPrefixOnlySerialize(a), addrPrefixOnlySerialize(b)) |
no test coverage detected
searching dependent graphs…