Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

nstgt/bgpbully

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bgpbully

bgpbully is a test tool for BGP.
It receives and sends BGP packets according to YAML syntax scenario, even if they are malformed.

Install

$ go get github.com/nstgt/bgpbully/cmd/bgpbully

Execution

Write config file and run with it.

$ bgpbully -f sample.yaml

Configuration

Configuration file is devided into 2 parts: global and scenario. See example.

In the global part, you neet to specify BGP connecting information.

global:
  peer_ip:   "127.0.0.1"  # IP address of remote BGP speaker in string
  peer_port: 179          # TCP port number of remoe BGP speaker in decimal number
  holdtime:  90           # hold time value in decimal number
  local_as:  65001        # local AS number in decimal number
  local_id:  "10.0.0.1"   # local router ID in string

In the scenario part, you can decide the BGP behavior of bgpbully by using instructions composed of operation (ope) and its parameter (param, if needed).

scenario:
- ope: 'Operation'
  param: 'Parameter'

Here is a list for available instructions:

Operation (ope) Parameter (param) Description
connect - connect to remote BGP speaker according to global configuration
sleep needed sleep given duration
close - close connection
send_bgp_open needed send BGP OPEN Message to the remote BGP speaker
send_bgp_update needed send BGP UPDATE Message to the remote BGP speaker
send_bgp_notification needed send BGP NOTIFICAYION Message to the remote BGP speaker
send_bgp_keepalive - send BGP KEEPALIVE Message to the remote BGP speaker
send_bgp_routerefresh needed send BGP ROUTEREFRESH Message to the remote BGP speaker
receive_bgp_open - wait for BGP OPEN Message from the remote BGP speaker
receive_bgp_update - wait for BGP UPDATE Message from the remote BGP speaker
receive_bgp_notification - wait for BGP NOTIFICATION Message from the remote BGP speaker
receive_bgp_keepalive - wait for BGP KEEPALIVE Message from the remote BGP speaker
receive_bgp_routerefresh - wait for BGP ROUTEREFRESH Message from the remote BGP speaker

Parameter for

sleep

param:
  sec: 10 #secounds in decimal number

send_bgp_open

param:
  capabilities:
  - type: 1            # capability type code in decimal number
    value: "00010001"  # capability data in hexadecimal string

Refer IANA: Capability Codes for capabilities[*].type.
No human writable interface for capabilities[*].value yet :(

send_bgp_update

param:
  nlri:             # array of advertised IP prefixes in string
  - "10.0.0.0/24"
  withdrawn_routes: # array of withdrawn IP prefixes in string
  - "10.0.0.0/24"
  path_attributes:  # array of path attribution like follows
  - flag: "40"      # path attribution flag in hexadecimal string
    type: 1         # path attribution type code in decimal number
    value: "00"     # path attribution value in hexadecimal string

Refer IANA: BGP Path Attributes for .path_attributes[*].type.
No human writable interface for path_attributes[*].value yet :(

send_bgp_notification

param:
  code: 1     # error code in decimal number
  subcode: 1  # error subcode in decimal number

Refer IANA: BGP Error (Notification) Codes for code and IANA: BGP Error Subcodes for subcode.

send_bgp_routerefresh

param:
  afi: 1   # address family indicator in decimal number
  safi: 1  # subsequent address family indicator in decimal number

Refer IANA: Address Family Numbers for afi and IANA: Subsequent Address Family Identifiers (SAFI) Parameters for safi.

receive_bgp_*

Currently, receive_bgp_* operations just validate BGP Message type of receiving BGP packet from the remote BGP speaker.

TODO

There are alot of TODOs.
I always welcome your feedbacks.

  • BGP
    • MD5
    • More flexible receive_* operation
    • Invalid length for Capability and Path Attribute
  • Others
    • Test
    • Human writable configuration
  • and more

Try

Also see Playground

Let's bully GoBGP.
You need to install GoBGP. If you don't have, see here.

Write config and start GoBGP.

$ cat > gobgpd.conf <<EOF
[global.config]
as = 64512
router-id = "10.0.0.100"

[[neighbors]]
  [neighbors.config]
      peer-as = 65001
      neighbor-address = "127.0.0.1"
      local-as = 64512
  [neighbors.transport.config]
      passive-mode = true
EOF

$ gobgpd -f gobgpd.conf
{"level":"info","msg":"gobgpd started","time":"2020-04-05T22:29:05+09:00"}
...

Run bgpbully using sample config.

$ bgpbully -f sample.yaml
2020/04/05 22:24:00 start
2020/04/05 22:24:00 connecting to 127.0.0.1:179
2020/04/05 22:24:00 send BGP Open Message
2020/04/05 22:24:00 receive BGP Message, type 1
2020/04/05 22:24:00 send BGP Keepalive Message
2020/04/05 22:24:00 receive BGP Message, type 4
2020/04/05 22:24:00 send BGP Update Message
2020/04/05 22:24:00 sleep 10 sec
2020/04/05 22:24:10 send BGP Update Message
2020/04/05 22:24:10 sleep 10 sec
2020/04/05 22:24:20 send BGP RouteRefresh Message
2020/04/05 22:24:20 sleep 10 sec
2020/04/05 22:24:30 send BGP Notification Message
2020/04/05 22:24:30 closing connection to 127.0.0.1:179

You'll see GoBGP establish BGP peer with bgpbully, and receive routes from it.

$ gobgp neighbor
Peer         AS  Up/Down State       |#Received  Accepted
127.0.0.1 65001 00:00:02 Establ      |        2         2

$ gobgp neighbor 127.0.0.1 adj-in
ID  Network              Next Hop             AS_PATH              Age        Attrs
0   10.0.0.0/24          10.0.0.1             65001                00:00:05   [{Origin: i}]
0   10.0.1.0/24          10.0.0.1             65001                00:00:05   [{Origin: i}]

## '10.0.0.0/24' was withdrawn
$  gobgp neighbor 127.0.0.1 adj-in
ID  Network              Next Hop             AS_PATH              Age        Attrs
0   10.0.1.0/24          10.0.0.1             65001                00:00:11   [{Origin: i}]

$ gobgp neighbor
Peer         AS  Up/Down State       |#Received  Accepted
127.0.0.1 65001 00:00:03 Idle        |        0         0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published