Skip to content
Snippets Groups Projects
update_sender_test.go 71.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • 			name:      "Normal withdraw with ADD-PATH",
    			addPathTX: true,
    			prefix:    bnet.NewPfx(bnet.IPv4(1413010532), 24),
    			path: &route.Path{
    
    				Type: route.BGPPathType,
    				BGPPath: &route.BGPPath{
    					PathIdentifier: 1,
    				},
    			},
    
    				0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
    				0x00, 0x1f, // BGP Message Length
    				0x02,       // BGP Message Type == Update
    				0x00, 0x08, // WithDraw Octet length
    				0x00, 0x00, 0x00, 0x01, // NLRI Path Identifier
    				0x18,             // Prefix Length
    				0x54, 0x38, 0xd4, // Prefix,
    				0x00, 0x00, // Total Path Attribute Length
    			},
    
    			expectedError: nil,
    		},
    		{
    			name:      "Normal withdraw without ADD-PATH",
    			addPathTX: false,
    			prefix:    bnet.NewPfx(bnet.IPv4(1413010532), 24),
    			path: &route.Path{
    				Type: route.BGPPathType,
    				BGPPath: &route.BGPPath{
    					PathIdentifier: 1,
    				},
    			},
    			expected: []byte{
    				0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
    				0x00, 0x1b, // BGP Message Length
    				0x02,       // BGP Message Type == Update
    				0x00, 0x04, // WithDraw Octet length
    				0x18,             // Prefix Length
    				0x54, 0x38, 0xd4, // Prefix,
    				0x00, 0x00, // Total Path Attribute Length
    			},
    			expectedError: nil,
    
    			name:      "Non bgp withdraw",
    			addPathTX: true,
    			prefix:    bnet.NewPfx(bnet.IPv4(1413010532), 24),
    			path: &route.Path{
    
    				Type: route.StaticPathType,
    			},
    
    			expected:      []byte{},
    			expectedError: errors.New("wrong path type, expected BGPPathType"),
    
    			name:      "Nil BGPPathType",
    			addPathTX: true,
    			prefix:    bnet.NewPfx(bnet.IPv4(1413010532), 24),
    			path: &route.Path{
    
    				Type: route.BGPPathType,
    			},
    
    			expected:      []byte{},
    			expectedError: errors.New("got nil BGPPath"),
    
    	for _, tc := range testcases {
    
    		t.Run(tc.name, func(t *testing.T) {
    			buf := bytes.NewBuffer([]byte{})
    
    			u := &UpdateSender{
    				fsm: &FSM{},
    				options: &packet.EncodeOptions{
    					UseAddPath: tc.addPathTX,
    				},
    			}
    
    			err := u.withdrawPrefixIPv4(buf, tc.prefix, tc.path)
    			assert.Equal(t, tc.expectedError, err, "error mismatch")
    			assert.Equal(t, tc.expected, buf.Bytes(), "expected different bytes")
    		})