github.com/vishvananda/netlink@v1.3.0/nl/link_linux_test.go (about)

     1  package nl
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/rand"
     6  	"encoding/binary"
     7  	"testing"
     8  )
     9  
    10  func (msg *VfMac) write(b []byte) {
    11  	native := NativeEndian()
    12  	native.PutUint32(b[0:4], uint32(msg.Vf))
    13  	copy(b[4:36], msg.Mac[:])
    14  }
    15  
    16  func (msg *VfMac) serializeSafe() []byte {
    17  	length := SizeofVfMac
    18  	b := make([]byte, length)
    19  	msg.write(b)
    20  	return b
    21  }
    22  
    23  func deserializeVfMacSafe(b []byte) *VfMac {
    24  	var msg = VfMac{}
    25  	binary.Read(bytes.NewReader(b[0:SizeofVfMac]), NativeEndian(), &msg)
    26  	return &msg
    27  }
    28  
    29  func TestVfMacDeserializeSerialize(t *testing.T) {
    30  	var orig = make([]byte, SizeofVfMac)
    31  	rand.Read(orig)
    32  	safemsg := deserializeVfMacSafe(orig)
    33  	msg := DeserializeVfMac(orig)
    34  	testDeserializeSerialize(t, orig, safemsg, msg)
    35  }
    36  
    37  func (msg *VfVlan) write(b []byte) {
    38  	native := NativeEndian()
    39  	native.PutUint32(b[0:4], uint32(msg.Vf))
    40  	native.PutUint32(b[4:8], uint32(msg.Vlan))
    41  	native.PutUint32(b[8:12], uint32(msg.Qos))
    42  }
    43  
    44  func (msg *VfVlan) serializeSafe() []byte {
    45  	length := SizeofVfVlan
    46  	b := make([]byte, length)
    47  	msg.write(b)
    48  	return b
    49  }
    50  
    51  func deserializeVfVlanSafe(b []byte) *VfVlan {
    52  	var msg = VfVlan{}
    53  	binary.Read(bytes.NewReader(b[0:SizeofVfVlan]), NativeEndian(), &msg)
    54  	return &msg
    55  }
    56  
    57  func TestVfVlanDeserializeSerialize(t *testing.T) {
    58  	var orig = make([]byte, SizeofVfVlan)
    59  	rand.Read(orig)
    60  	safemsg := deserializeVfVlanSafe(orig)
    61  	msg := DeserializeVfVlan(orig)
    62  	testDeserializeSerialize(t, orig, safemsg, msg)
    63  }
    64  
    65  func (msg *VfTxRate) write(b []byte) {
    66  	native := NativeEndian()
    67  	native.PutUint32(b[0:4], uint32(msg.Vf))
    68  	native.PutUint32(b[4:8], uint32(msg.Rate))
    69  }
    70  
    71  func (msg *VfTxRate) serializeSafe() []byte {
    72  	length := SizeofVfTxRate
    73  	b := make([]byte, length)
    74  	msg.write(b)
    75  	return b
    76  }
    77  
    78  func deserializeVfTxRateSafe(b []byte) *VfTxRate {
    79  	var msg = VfTxRate{}
    80  	binary.Read(bytes.NewReader(b[0:SizeofVfTxRate]), NativeEndian(), &msg)
    81  	return &msg
    82  }
    83  
    84  func TestVfTxRateDeserializeSerialize(t *testing.T) {
    85  	var orig = make([]byte, SizeofVfTxRate)
    86  	rand.Read(orig)
    87  	safemsg := deserializeVfTxRateSafe(orig)
    88  	msg := DeserializeVfTxRate(orig)
    89  	testDeserializeSerialize(t, orig, safemsg, msg)
    90  }
    91  
    92  func (msg *VfRate) write(b []byte) {
    93  	native := NativeEndian()
    94  	native.PutUint32(b[0:4], uint32(msg.Vf))
    95  	native.PutUint32(b[4:8], uint32(msg.MinTxRate))
    96  	native.PutUint32(b[8:12], uint32(msg.MaxTxRate))
    97  }
    98  
    99  func (msg *VfRate) serializeSafe() []byte {
   100  	length := SizeofVfRate
   101  	b := make([]byte, length)
   102  	msg.write(b)
   103  	return b
   104  }
   105  
   106  func deserializeVfRateSafe(b []byte) *VfRate {
   107  	var msg = VfRate{}
   108  	binary.Read(bytes.NewReader(b[0:SizeofVfRate]), NativeEndian(), &msg)
   109  	return &msg
   110  }
   111  
   112  func TestVfRateDeserializeSerialize(t *testing.T) {
   113  	var orig = make([]byte, SizeofVfRate)
   114  	rand.Read(orig)
   115  	safemsg := deserializeVfRateSafe(orig)
   116  	msg := DeserializeVfRate(orig)
   117  	testDeserializeSerialize(t, orig, safemsg, msg)
   118  }
   119  
   120  func (msg *VfSpoofchk) write(b []byte) {
   121  	native := NativeEndian()
   122  	native.PutUint32(b[0:4], uint32(msg.Vf))
   123  	native.PutUint32(b[4:8], uint32(msg.Setting))
   124  }
   125  
   126  func (msg *VfSpoofchk) serializeSafe() []byte {
   127  	length := SizeofVfSpoofchk
   128  	b := make([]byte, length)
   129  	msg.write(b)
   130  	return b
   131  }
   132  
   133  func deserializeVfSpoofchkSafe(b []byte) *VfSpoofchk {
   134  	var msg = VfSpoofchk{}
   135  	binary.Read(bytes.NewReader(b[0:SizeofVfSpoofchk]), NativeEndian(), &msg)
   136  	return &msg
   137  }
   138  
   139  func TestVfSpoofchkDeserializeSerialize(t *testing.T) {
   140  	var orig = make([]byte, SizeofVfSpoofchk)
   141  	rand.Read(orig)
   142  	safemsg := deserializeVfSpoofchkSafe(orig)
   143  	msg := DeserializeVfSpoofchk(orig)
   144  	testDeserializeSerialize(t, orig, safemsg, msg)
   145  }
   146  
   147  func (msg *VfLinkState) write(b []byte) {
   148  	native := NativeEndian()
   149  	native.PutUint32(b[0:4], uint32(msg.Vf))
   150  	native.PutUint32(b[4:8], uint32(msg.LinkState))
   151  }
   152  
   153  func (msg *VfLinkState) serializeSafe() []byte {
   154  	length := SizeofVfLinkState
   155  	b := make([]byte, length)
   156  	msg.write(b)
   157  	return b
   158  }
   159  
   160  func deserializeVfLinkStateSafe(b []byte) *VfLinkState {
   161  	var msg = VfLinkState{}
   162  	binary.Read(bytes.NewReader(b[0:SizeofVfLinkState]), NativeEndian(), &msg)
   163  	return &msg
   164  }
   165  
   166  func TestVfLinkStateDeserializeSerialize(t *testing.T) {
   167  	var orig = make([]byte, SizeofVfLinkState)
   168  	rand.Read(orig)
   169  	safemsg := deserializeVfLinkStateSafe(orig)
   170  	msg := DeserializeVfLinkState(orig)
   171  	testDeserializeSerialize(t, orig, safemsg, msg)
   172  }
   173  
   174  func (msg *VfRssQueryEn) write(b []byte) {
   175  	native := NativeEndian()
   176  	native.PutUint32(b[0:4], uint32(msg.Vf))
   177  	native.PutUint32(b[4:8], uint32(msg.Setting))
   178  }
   179  
   180  func (msg *VfRssQueryEn) serializeSafe() []byte {
   181  	length := SizeofVfRssQueryEn
   182  	b := make([]byte, length)
   183  	msg.write(b)
   184  	return b
   185  }
   186  
   187  func deserializeVfRssQueryEnSafe(b []byte) *VfRssQueryEn {
   188  	var msg = VfRssQueryEn{}
   189  	binary.Read(bytes.NewReader(b[0:SizeofVfRssQueryEn]), NativeEndian(), &msg)
   190  	return &msg
   191  }
   192  
   193  func TestVfRssQueryEnDeserializeSerialize(t *testing.T) {
   194  	var orig = make([]byte, SizeofVfRssQueryEn)
   195  	rand.Read(orig)
   196  	safemsg := deserializeVfRssQueryEnSafe(orig)
   197  	msg := DeserializeVfRssQueryEn(orig)
   198  	testDeserializeSerialize(t, orig, safemsg, msg)
   199  }