5 # This script creates an UDP socket and starts listening on it.
6 # When a map-request is received nonce is extracted from the request and
10 # * works only with ipv4 in both under/over-lays.
11 # * exact address matching is done while looking for a mapping
14 # ./dummy_mr <bind-ip> <port>
20 # mapping between EIDs and RLOCs
22 b'\x06\x00\x02\x02' : (b'\x06\x00\x03\x02', ),
23 b'\x06\x00\x01\x02' : (b'\x06\x00\x03\x01', )
26 # LISP map-reply message
27 reply_data = (b'\x20\x00\x00\x01' # type, PES, reserved, record count
28 + '\x00\x00\x00\x00' # nonce
29 + '\x00\x00\x00\x00' # nonce
30 + '\x00\x00\x05\xa0' # record TTL
31 + '\x01\x18\x10\x00' # loc-count, EID-len, ACT
32 + '\x00\x00\x00\x01' # rsvd, map-version, EID-AFI=ipv4
33 + '\x06\x00\x02\x00' # EID prefix
34 + '\x01\x01\xff\x00' # prio, weight, mprio, mweight
35 + '\x00\x05\x00\x01' # unused, LpR, Loc-AFI
36 + '\x06\x00\x03\x02') # locator
38 request_nonce_offset = 36
39 reply_nonce_offset = 4
41 request_eid_offset = 60
44 reply_rloc_offset = 36
47 def build_reply(nonce, deid):
48 if deid not in mappings:
49 raise Exception('No mapping found for eid {}!'.format(repr(deid)))
53 reply = bytearray(reply_data)
55 # update rloc field in reply message
56 rloc = bytearray(m[0])
59 reply[reply_rloc_offset + i] = rloc[i]
61 # update eid prefix field
63 reply[reply_eid_offset + i] = deid[i]
67 reply[reply_nonce_offset + i] = nonce[i]
73 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
74 server_address = (host, int(port))
75 sock.bind(server_address)
78 data, address = sock.recvfrom(4096)
80 # extract nonce from request
81 nonce = data[request_nonce_offset:request_nonce_offset+8]
84 deid = data[request_eid_offset:request_eid_offset+4]
86 rp = build_reply(nonce, deid)
87 sock.sendto(rp, address)
90 if __name__ == "__main__":
92 raise Exception('IP and port expected')
94 run(sys.argv[1], sys.argv[2])