diff options
10 files changed, 207 insertions, 18 deletions
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py index 056cdd01..baff3109 100644 --- a/test/scenario_test/docker_control.py +++ b/test/scenario_test/docker_control.py @@ -16,7 +16,6 @@ from fabric.api import local import re import os -import sys GOBGP_CONTAINER_NAME = "gobgp" GOBGP_ADDRESS = "10.0.255.1/16" @@ -75,7 +74,6 @@ def install_docker_and_tools(): local("docker pull osrg/gobgp", capture=True) local("docker pull osrg/exabgp", capture=True) local("mkdir /usr/local/gobgp", capture=True) - # local("docker run --privileged=true -v /usr/local/gobgp:/mnt --name gobgp --rm osrg/gobgp go run /root/gobgp/tools/route-server/quagga-rsconfig.go -c /mnt", capture=True) def docker_pkg_check(): @@ -83,7 +81,6 @@ def docker_pkg_check(): outbuf = local("dpkg -l | grep docker | awk '{print $2}'", capture=True) dpkg_list = outbuf.split('\n') for dpkg in dpkg_list: - # print "lxc-docker in ",dpkg if "lxc-docker" in dpkg: docker_exists = True return docker_exists @@ -248,13 +245,12 @@ def bridge_unsetting_for_docker_connection(): def start_gobgp(): cmd = "docker exec gobgp " + STARTUP_FILE + " > /dev/null 2>&1 &" - # cmd = "docker exec gobgp " + STARTUP_FILE local(cmd, capture=True) def start_exabgp(conf_file): conf_path = EXABGP_CONFDIR + conf_file - cmd = "docker exec exabgp /usr/local/exabgp/sbin/exabgp " + conf_path + " > /dev/null 2>&1 &" + cmd = "docker exec exabgp /root/exabgp/sbin/exabgp " + conf_path + " > /dev/null 2>&1 &" local(cmd, capture=True) @@ -341,6 +337,13 @@ def init_malformed_test_env_executor(conf_file, use_local): gobgp_file = pwd + "/exabgp_test_conf/gobgpd.conf" cmd = "cp " + gobgp_file + " " + CONFIG_DIRR local(cmd, capture=True) + quagga_dir = CONFIG_DIRR + "q1" + cmd = "mkdir " + quagga_dir + local(cmd, capture=True) + quagga_file = pwd + "/exabgp_test_conf/quagga.conf" + cmd = "cp " + quagga_file + " " + quagga_dir + "/bgpd.conf" + local(cmd, capture=True) + docker_container_run_quagga(1, BRIDGE_0) docker_container_run_gobgp(BRIDGE_0) docker_container_run_exabgp(BRIDGE_0) diff --git a/test/scenario_test/exabgp_test_conf/gobgpd.conf b/test/scenario_test/exabgp_test_conf/gobgpd.conf index 31c37640..27da5ba7 100644 --- a/test/scenario_test/exabgp_test_conf/gobgpd.conf +++ b/test/scenario_test/exabgp_test_conf/gobgpd.conf @@ -73,6 +73,70 @@ EstablishedCount = 0 DroppedCount = 0 +[[NeighborList]] + NeighborAddress = "10.0.0.1" + PeerAs = 65001 + Description = "" + AuthPassword = "hoge1" + PeerType = 0 + RemovePrivateAs = 0 + RouteFlapDamping = false + [NeighborList.RouteSelectionOptions] + AlwaysCompareMed = false + IgnoreAsPathLength = false + ExternalCompareRouterId = false + AdvertiseInactiveRoutes = false + EnableAigp = false + [NeighborList.UseMultiplePaths] + [NeighborList.UseMultiplePaths.Ebgp] + AllowMultipleAs = false + MaximumPaths = 0 + [NeighborList.UseMultiplePaths.Ibgp] + MaximumPaths = 0 + [NeighborList.UseMultiplePaths.Eibgp] + MaximumPaths = 0 + [NeighborList.GracefulRestart] + RestartTime = 0 + StaleRoutesTime = 0.0 + [NeighborList.ApplyPolicy] + [NeighborList.Timers] + ConnectRetry = 0.0 + HoldTime = 0.0 + KeepaliveInterval = 0.0 + MinimumAdvertisementInterval = 0.0 + SendUpdateDelay = 0.0 + [NeighborList.EbgpMultihop] + MultihopTtl = 0 + [NeighborList.RouteReflector] + RouteReflectorClusterId = 0 + RouteReflectorClient = false + [NeighborList.BgpLoggingOptions] + LogNeighborStateChanges = false + [NeighborList.TransportOptions] + TcpMss = 0 + MtuDiscovery = false + PassiveMode = false + [NeighborList.BgpNeighborCommonState] + State = 0 + Uptime = 0001-01-01T00:00:00Z + OpenIn = 0 + OpenOut = 0 + UpdateIn = 0 + UpdateOut = 0 + UpdateRecvTime = 0001-01-01T00:00:00Z + KeepaliveIn = 0 + KeepaliveOut = 0 + NotifyIn = 0 + NotifyOut = 0 + RefreshIn = 0 + RefreshOut = 0 + DynamicCapIn = 0 + DynamicCapOut = 0 + TotalIn = 0 + TotalOut = 0 + EstablishedCount = 0 + DroppedCount = 0 + [Policy] [Policy.DefinedSets] [Policy.PolicyDefinitions] diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS4_PATH.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS4_PATH.conf index 79502e78..b6b05cfd 100644 --- a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS4_PATH.conf +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS4_PATH.conf @@ -11,8 +11,6 @@ neighbor 10.0.255.1 { inet unicast; } static { - route 172.16.13.0/24 next-hop 10.0.0.120; - route 192.168.100.100 next-hop 10.0.0.110; # malformed AS4_PATH route 10.7.0.17/32 next-hop 10.0.255.7 attribute [ 0x11 0x60 0x11223344 ]; } diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS_PATH.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS_PATH.conf index a241c71f..46ab6da0 100644 --- a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS_PATH.conf +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-AS_PATH.conf @@ -11,8 +11,6 @@ neighbor 10.0.255.1 { inet unicast; } static { - route 172.16.13.0/24 next-hop 10.0.0.120; - route 192.168.100.100 next-hop 10.0.0.110; # malformed AS_PATH route 10.7.0.2/32 next-hop 10.0.255.7 attribute [ 0x02 0x60 0x11223344 ]; } diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf index 95ea6ba1..58cc3833 100644 --- a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf @@ -11,9 +11,7 @@ neighbor 10.0.255.1 { inet unicast; } static { - route 172.16.13.0/24 next-hop 10.0.0.120; - route 192.168.100.100 next-hop 10.0.0.110; - # malformed MP_UNREACH_NLRI - route 10.7.0.15/32 next-hop 10.0.255.7 attribute [ 0x0f 0x60 0x11223344 ]; + # malformed MP_REACH_NLRI + route 10.7.0.14/32 next-hop 10.0.255.7 attribute [ 0x0e 0x60 0x11223344 ]; } } diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_UNREACH_NLRI.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_UNREACH_NLRI.conf new file mode 100644 index 00000000..7bd90117 --- /dev/null +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-MP_UNREACH_NLRI.conf @@ -0,0 +1,18 @@ +neighbor 10.0.255.1 { + router-id 192.168.0.7; + local-address 10.0.0.100; + local-as 65100; + peer-as 65000; + hold-time 90; + md5 "hoge100"; + graceful-restart; + + family { + inet unicast; + } + + static { + # malformed MP_UNREACH_NLRI + route 10.7.0.15/32 next-hop 10.0.255.7 attribute [ 0x0f 0x60 0x11223344 ]; + } +}
\ No newline at end of file diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-NEXTHOP_INVALID.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-NEXTHOP_INVALID.conf new file mode 100644 index 00000000..1b689d2b --- /dev/null +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-NEXTHOP_INVALID.conf @@ -0,0 +1,28 @@ +group AS65070 { + neighbor 10.0.255.1 { + router-id 192.168.0.7; + local-address 10.0.0.100; + local-as 65100; + peer-as 65000; + hold-time 90; + md5 "hoge100"; + + family { + inet unicast; + } + + static { + route 10.0.0.7/32 { + # 0x0e: MP_REACH_NLRI + # 0x60: Optional, Transitive + # 0x01: AFI(IPv4) + # 0x01: SAFI(unicast) + # 0x10: Length of Next Hop Address + # 0xffffff00: Network address of Next Hop + # 0x00: Reserved + next-hop 10.0.255.7; + attribute [ 0x0e 0x60 0x010110ffffff0000 ]; + } + } + } +}
\ No newline at end of file diff --git a/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-ROUTE_FAMILY_INVALID.conf b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-ROUTE_FAMILY_INVALID.conf new file mode 100644 index 00000000..fe52b0c2 --- /dev/null +++ b/test/scenario_test/exabgp_test_conf/malformed1-exabgp-gobgp-v4-ROUTE_FAMILY_INVALID.conf @@ -0,0 +1,29 @@ +group AS65070 { + neighbor 10.0.255.1 { + router-id 192.168.0.7; + local-address 10.0.0.100; + local-as 65100; + peer-as 65000; + hold-time 90; + md5 "hoge100"; + + family { + inet unicast; + } + + static { + route 10.0.0.7/32 next-hop 10.0.255.7 attribute [ 0x0e 0x60 0x0002011020010db800000000000000000000000100 ]; + #route 10.0.0.7/32 { + # 0x0e: MP_REACH_NLRI + # 0x60: Optional, Transitive + # 0x01: AFI(IPv4) + # 0x01: SAFI(unicast) + # 0x10: Length of Next Hop Address + # 0xffffff00: Network address of Next Hop + # 0x00: Reserved + #next-hop 10.0.255.7; + #attribute [ 0x0e 0x60 0x0002011020010db800000000000000000000000100 ]; + #} + } + } +}
\ No newline at end of file diff --git a/test/scenario_test/exabgp_test_conf/quagga.conf b/test/scenario_test/exabgp_test_conf/quagga.conf new file mode 100644 index 00000000..03f43202 --- /dev/null +++ b/test/scenario_test/exabgp_test_conf/quagga.conf @@ -0,0 +1,7 @@ +hostname bgpd +password zebra +router bgp 65001 +bgp router-id 192.168.0.1 +network 192.168.1.0/24 +neighbor 10.0.255.1 remote-as 65000 +neighbor 10.0.255.1 password hoge1
\ No newline at end of file diff --git a/test/scenario_test/route_server_malformed_test.py b/test/scenario_test/route_server_malformed_test.py index 4a2d90b6..05ed601d 100644 --- a/test/scenario_test/route_server_malformed_test.py +++ b/test/scenario_test/route_server_malformed_test.py @@ -20,11 +20,17 @@ import sys import nose import collections import docker_control as fab +import requests +import json +import toml from noseplugin import OptionParser from noseplugin import parser_option sleep_time = 20 +gobgp_ip = "10.0.255.1" +gobgp_port = "8080" +gobgp_config_file = "/usr/local/gobgp/gobgpd.conf" def check_pattern(): @@ -35,9 +41,12 @@ def check_pattern(): pattern["<File to be used in test>"] = "<at that time the message>" """ pattern = collections.OrderedDict() - pattern["malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf"] = "UPDATE message error / Attribute Flags Error / 0x600F0411223344" + pattern["malformed1-exabgp-gobgp-v4-MP_REACH_NLRI.conf"] = "UPDATE message error / Attribute Flags Error / 0x600E0411223344" + pattern["malformed1-exabgp-gobgp-v4-MP_UNREACH_NLRI.conf"] = "UPDATE message error / Attribute Flags Error / 0x600F0411223344" pattern["malformed1-exabgp-gobgp-v4-AS_PATH.conf"] = "UPDATE message error / Attribute Flags Error / 0x60020411223344" pattern["malformed1-exabgp-gobgp-v4-AS4_PATH.conf"] = "UPDATE message error / Attribute Flags Error / 0x60110411223344" + pattern["malformed1-exabgp-gobgp-v4-NEXTHOP_INVALID.conf"] = "UPDATE message error / Attribute Flags Error / 0x600E08010110FFFFFF0000" + pattern["malformed1-exabgp-gobgp-v4-ROUTE_FAMILY_INVALID.conf"] = "UPDATE message error / Attribute Flags Error / 0x600E150002011020010DB800000000000000000000000100" return pattern @@ -59,7 +68,6 @@ def test_malformed_packet(): sys.exit(1) use_local = parser_option.use_local - go_path = parser_option.go_path for pkey in pattern: conf_file = pwd + "/exabgp_test_conf/" + pkey @@ -67,7 +75,7 @@ def test_malformed_packet(): fab.init_malformed_test_env_executor(pkey, use_local) print "please wait" time.sleep(sleep_time) - yield check_em, pkey, pattern[pkey] + yield check_func, pkey, pattern[pkey] else: print "config file not exists." @@ -75,9 +83,30 @@ def test_malformed_packet(): sys.exit(1) -def check_em(exabgp_conf, result): +def check_func(exabgp_conf, result): + # get neighbor addresses from gobgpd.conf + addresses = get_neighbor_address() + # check whether the service of gobgp is normally + url = "http://" + gobgp_ip + ":" + gobgp_port + "/v1/bgp/neighbors" + r = requests.get(url) + neighbors = json.loads(r.text) + + assert len(neighbors) == len(addresses) + + for neighbor in neighbors: + state = neighbor['info']['bgp_state'] + remote_ip = neighbor['conf']['remote_ip'] + e_transitions = neighbor['info']['fsm_established_transitions'] + if remote_ip == "10.0.0.1": + print "check of [ " + remote_ip + " ]" + assert state == "BGP_FSM_ESTABLISHED" + assert e_transitions == 1 + else: + print "check of [ " + remote_ip + " ]" + assert remote_ip == "10.0.0.100" + + # get notification message from exabgp log err_msg = fab.get_notification_from_exabgp_log() - # parse_msg = re.search(r'error.*', err_msg).group(0) notification = None parse_msg = re.search(r'error.*', err_msg) if parse_msg is not None: @@ -87,8 +116,25 @@ def check_em(exabgp_conf, result): print "notification message : " print " >>> " + str(notification) + # check notification messege assert notification == result + +# get address of each neighbor from gobpg configration +def get_neighbor_address(): + address = [] + try: + gobgp_config = toml.loads(open(gobgp_config_file).read()) + neighbors_config = gobgp_config['NeighborList'] + for neighbor_config in neighbors_config: + neighbor_ip = neighbor_config['NeighborAddress'] + address.append(neighbor_ip) + + except IOError, (errno, strerror): + print "I/O error(%s): %s" % (errno, strerror) + + return address + if __name__ == '__main__': if fab.test_user_check() is False: print "you are not root." |