Add map server fallback test 13/7913/1
authorFilip Tehlar <ftehlar@cisco.com>
Fri, 4 Aug 2017 11:12:57 +0000 (13:12 +0200)
committerFilip Tehlar <ftehlar@cisco.com>
Fri, 4 Aug 2017 11:12:57 +0000 (13:12 +0200)
Change-Id: I48bf31b15253a1b9d1be785af319ef7466fa50bd
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp1.config [new file with mode: 0644]
tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp2.config [new file with mode: 0644]
tests/data_plane/vpp_lite_topo/config.sh
tests/data_plane/vpp_lite_topo/scripts/dummy_map_server.py [new file with mode: 0644]
tests/data_plane/vpp_lite_topo/test_driver/basic.sh
tests/data_plane/vpp_lite_topo/tests/manual_test_map_register_fallback_4o4.sh [new file with mode: 0755]

diff --git a/tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp1.config b/tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp1.config
new file mode 100644 (file)
index 0000000..d12cd42
--- /dev/null
@@ -0,0 +1,9 @@
+create_host_iface vpp1 6.0.1.1/24
+create_host_iface intervpp1 6.0.3.1/24
+
+lisp_state enable
+lisp_locator_set_with_locator ls1 host-intervpp1 1 1
+lisp_local_eid eid 6.0.1.0/24 locator-set ls1 secret-key password key-id sha1
+lisp_map_server 6.0.3.100
+lisp_map_server 6.0.3.200
+lisp_map_register_state enable
diff --git a/tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp2.config b/tests/data_plane/configs/vpp_lite_config/basic/4o4_map_register_fallback/vpp2.config
new file mode 100644 (file)
index 0000000..61a971a
--- /dev/null
@@ -0,0 +1,8 @@
+create_host_iface vpp2 6.0.2.1/24
+create_host_iface intervpp2 6.0.3.2/24
+
+lisp_state enable
+lisp_locator_set_with_locator ls1 host-intervpp2 1 1
+lisp_local_eid eid 6.0.2.0/24 locator-set ls1 secret-key password2 key-id sha256
+lisp_map_server 6.0.3.100
+lisp_map_resolver 6.0.3.100
index f2f8502..0c5dfc4 100644 (file)
@@ -162,6 +162,13 @@ function start_map_resolver
   mr_id=$!
 }
 
+function start_map_server
+{
+  echo "starting dummy map server on interface $1"
+  python scripts/dummy_map_server.py "$1" 4342 &
+  ms_id=$!
+}
+
 function check_counters
 {
   python scripts/vat/check_counters.py ${VPP_API_TEST} ${VAT_TEMPLATES} "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
diff --git a/tests/data_plane/vpp_lite_topo/scripts/dummy_map_server.py b/tests/data_plane/vpp_lite_topo/scripts/dummy_map_server.py
new file mode 100644 (file)
index 0000000..886e412
--- /dev/null
@@ -0,0 +1,66 @@
+# Usage:
+#
+#   $ python dummy_map_server <bind-ip> <port>
+#
+
+import sys
+import socket
+import hmac
+import hashlib
+
+map_notify = (b"\x40\x00\x00\x01"
+    + "\x00\x00\x00\x00"
+    + "\x00\x00\x00\x00"
+    + "\x00\x01\x00\x14"  # key ID, Auth data length = 20
+    + "\x00\x00\x00\x00"
+    + "\x00\x00\x00\x00"
+    + "\x00\x00\x00\x00"
+    + "\x00\x00\x00\x00"
+    + "\x00\x00\x00\x00" # auth data
+    + "\x00\x01"
+    + "\x51\x80\x01\x18\x00\x00\x00\x00\x00\x01\x06\x00\x01\x00\x01\x01"
+    + "\x00\x00\x00\x04\x00\x01\x06\x00\x03\x01")
+
+notify_nonce_offset = 4
+notify_auth_data_len = 20
+register_nonce_offset = 4
+auth_data_offset = 16
+secret_key = 'password'
+
+
+def build_notify(nonce):
+  rp = bytearray(map_notify)
+
+  for i in range(0, 8):
+    rp[notify_nonce_offset + i] = nonce[i]
+
+  # compute hash
+  digest = hmac.new(secret_key, rp, hashlib.sha1).digest()
+
+  for i in range(0, notify_auth_data_len):
+    rp[auth_data_offset + i] = digest[i]
+
+  return rp
+
+
+def run(host, port):
+  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+  server_address = (host, int(port))
+  sock.bind(server_address)
+
+  while True:
+    data, address = sock.recvfrom(4096)
+
+    # extract nonce from message
+    nonce = data[register_nonce_offset:register_nonce_offset+8]
+
+    rp = build_notify(nonce)
+    sock.sendto(rp, address)
+    print 'Replied to ', ''.join(x.encode('hex') for x in nonce)
+
+
+if __name__ == "__main__":
+  if len(sys.argv) < 2:
+    raise Exception('IP and port expected')
+
+  run(sys.argv[1], sys.argv[2])
index 0cdf10d..0575bb3 100644 (file)
@@ -47,6 +47,39 @@ function test_basic
   exit $test_result
 }
 
+function test_basic_map_register_fallback
+{
+  2_node_topo_setup no_odl
+
+  maybe_pause
+
+  test_result=1
+
+  start_map_server "6.0.3.200"
+
+  wait_for_map_register=20
+  echo "Waiting for map registration $wait_for_map_register seconds .."
+  sleep $wait_for_map_register
+
+  rc=1
+
+  count="`echo "show error" | nc 0 5002 | grep 'map-notifies received' | awk '{print $1}'`"
+  if [ "$count" != "" ] ; then
+    if [ $count -gt 0 ] ; then
+      echo "no map-notifies received! ($count)"
+      rc=0 # test passed
+    fi
+  fi
+
+  maybe_pause
+  kill $ms_id
+
+  # test done
+  2_node_topo_clean no_odl
+  print_status $rc "map server fallback does not work!"
+  exit $test_result
+}
+
 function test_basic_map_register
 {
   2_node_topo_setup no_odl
diff --git a/tests/data_plane/vpp_lite_topo/tests/manual_test_map_register_fallback_4o4.sh b/tests/data_plane/vpp_lite_topo/tests/manual_test_map_register_fallback_4o4.sh
new file mode 100755 (executable)
index 0000000..8685fd2
--- /dev/null
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+# Test LISP map register feature (ip4 over ip4)
+
+VPP_LITE_CONF=`pwd`/../configs/vpp_lite_config/basic/4o4_map_register_fallback
+
+source test_driver/basic.sh
+
+test_basic_map_register_fallback ping "6.0.2.2"