Skip to content

Commit

Permalink
Add Nfdc functionality to enable working with FaceID rather than Face…
Browse files Browse the repository at this point in the history
…URI exclusively

refs: #5130

Change-Id: I1b7ca1846cafdde8e959663ba53d5bd50b455b39
  • Loading branch information
awlane authored and dulalsaurab committed Dec 19, 2021
1 parent 2085544 commit 1d3c0a8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
3 changes: 1 addition & 2 deletions docs/hackathon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Past NDN Hackathon projects
- 4th NDN Hackathon: `Mini-NDN wifi <https://github.com/4th-ndn-hackathon/Mini-NDN-Wi-Fi>`_.
- 7th NDN Hackathon: `Mini-NDN documentation <https://github.com/7th-ndn-hackathon/mini-ndn-documentation>`_.
- 11th NDN Hackathon: `Mini-NDN improvements <https://11th-ndn-hackathon.named-data.net/hacks.html#8-mini-ndn-improvements>`_.
- 12th NDN Hackathon: `Mini-NDN improvements and Refactoring <https://12th-ndn-hackathon.named-data.net/hacks.html#7-mini-ndn-improvements>`_.

- 12th NDN Hackathon: `Mini-NDN improvements and Refactoring <https://12th-ndn-hackathon.named-data.net/hacks.html#7-mini-ndn-improvements>`_.
4 changes: 2 additions & 2 deletions examples/psync/full_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def registerRouteToAllNeighbors(ndn, host, syncPrefix):
for node in ndn.net.hosts:
for neighbor in node.connectionsTo(host):
ip = node.IP(neighbor[0])
Nfdc.createFace(host, ip)
Nfdc.registerRoute(host, syncPrefix, ip)
faceID = Nfdc.createFace(host, ip)
Nfdc.registerRoute(host, syncPrefix, faceID)

if __name__ == '__main__':
setLogLevel('info')
Expand Down
4 changes: 2 additions & 2 deletions examples/wifi/wifi_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def runExperiment():

info("Starting pingserver...")
NDNPing.startPingServer(b, "/example")
Nfdc.createFace(a, b.IP())
Nfdc.registerRoute(a, "/example", b.IP())
faceID = Nfdc.createFace(a, b.IP())
Nfdc.registerRoute(a, "/example", faceID)

info("Starting ping...")
NDNPing.ping(a, "/example", nPings=10)
Expand Down
4 changes: 2 additions & 2 deletions minindn/helpers/ndn_routing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def routeAdd(self, node, neighborIPs):
prefixes = [defaultPrefix] + self.namePrefixes[destination]
for prefix in prefixes:
# Register routes to all the available destination name prefix/s
nfdc.registerRoute(node, prefix, neighborIPs[nextHop], \
nfdc.PROTOCOL_UDP, cost=cost)
faceID = nfdc.createFace(node, neighborIPs[nextHop])
nfdc.registerRoute(node, prefix, faceID, cost=cost)
@staticmethod
def getNeighbor(node):
# Nodes to IP mapping
Expand Down
74 changes: 57 additions & 17 deletions minindn/helpers/nfdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,65 @@ class Nfdc(object):
PROTOCOL_ETHER = 'ether'

@staticmethod
def registerRoute(node, namePrefix, remoteNodeAddress, protocol=PROTOCOL_UDP, origin=255,
def registerRoute(node, namePrefix, remoteNode, protocol=PROTOCOL_UDP, origin=255,
cost=0, inheritFlag=True, captureFlag=False, expirationInMillis=None):
cmd = ('nfdc route add {} {}://{} origin {} cost {} {}{}{}').format(
namePrefix,
protocol,
remoteNodeAddress,
origin,
cost,
'no-inherit ' if not inheritFlag else '',
'capture ' if captureFlag else '',
'expires {}'.format(expirationInMillis) if expirationInMillis else ''
)

cmd = ""
if remoteNode.isdigit() and not protocol == "fd":
cmd = ('nfdc route add {} {} origin {} cost {} {}{}{}').format(
namePrefix,
remoteNode,
origin,
cost,
'no-inherit ' if not inheritFlag else '',
'capture ' if captureFlag else '',
'expires {}'.format(expirationInMillis) if expirationInMillis else ''
)
else:
cmd = ('nfdc route add {} {}://{} origin {} cost {} {}{}{}').format(
namePrefix,
protocol,
remoteNode,
origin,
cost,
'no-inherit ' if not inheritFlag else '',
'capture ' if captureFlag else '',
'expires {}'.format(expirationInMillis) if expirationInMillis else ''
)
debug(node.cmd(cmd))
Minindn.sleep(SLEEP_TIME)

@staticmethod
def unregisterRoute(node, namePrefix, remoteNodeAddress, origin=255):
cmd = 'nfdc route remove {} {} {}'.format(namePrefix, remoteNodeAddress, origin)
def unregisterRoute(node, namePrefix, remoteNode, origin=255):
cmd = ""
if remoteNode.isdigit() and not protocol == "fd":
cmd = 'nfdc route remove {} {} {}'.format(namePrefix, remoteNode, origin)
else:
cmd = 'nfdc route remove {} {} {}'.format(namePrefix, remoteNode, origin)
debug(node.cmd(cmd))
Minindn.sleep(SLEEP_TIME)

@staticmethod
def createFace(node, remoteNodeAddress, protocol='udp', isPermanent=False):
'''Create face in node's NFD instance. Returns FaceID of created face or -1 if failed.'''
cmd = ('nfdc face create {}://{} {}'.format(
protocol,
remoteNodeAddress,
'permanent' if isPermanent else 'persistent'
))
debug(node.cmd(cmd))
output = node.cmd(cmd)
debug(output)
Minindn.sleep(SLEEP_TIME)
if "face-created" not in output:
return -1
faceID = output.split(" ")[1][3:]
return faceID

@staticmethod
def destroyFace(node, remoteNodeAddress, protocol='udp'):
debug(node.cmd('nfdc face destroy {}://{}'.format(protocol, remoteNodeAddress)))
def destroyFace(node, remoteNode, protocol='udp'):
if remoteNode.isdigit() and not protocol == "fd":
debug(node.cmd('nfdc face destroy {}'.format(protocol, remoteNode)))
else:
debug(node.cmd('nfdc face destroy {}://{}'.format(protocol, remoteNode)))
Minindn.sleep(SLEEP_TIME)

@staticmethod
Expand All @@ -83,3 +107,19 @@ def setStrategy(node, namePrefix, strategy):
def unsetStrategy(node, namePrefix):
debug(node.cmd("nfdc strategy unset {}".format(namePrefix)))
Minindn.sleep(SLEEP_TIME)

@staticmethod
def getFaceId(node, remoteNodeAddress, localEndpoint=None, protocol="udp", portNum="6363"):
'''Returns the faceId for a remote node based on FaceURI, or -1 if a face is not found'''
#Should this be cached or is the hit not worth it?
local = ""
if localEndpoint:
local = " local {}".format(localEndpoint)
output = node.cmd("nfdc face list remote {}://{}:{}{}".format(protocol, remoteNodeAddress, portNum, local))
debug(output)
Minindn.sleep(SLEEP_TIME)
# This is fragile but we don't have that many better options
if "faceid=" not in output:
return -1
faceId = output.split(" ")[0][7:]
return faceId

0 comments on commit 1d3c0a8

Please sign in to comment.