Add Nfdc functionality to enable working with FaceID rather than FaceURI exclusively
refs: #5130 Change-Id: I1b7ca1846cafdde8e959663ba53d5bd50b455b39
This commit is contained in:
1 parent
2085544799
commit
1d3c0a8ac5
5 files changed
+64
-25
No files matched your search
+1
-2
@@ -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>`_.
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -357,8 +357,8 @@ class NdnRoutingHelper(object):
|
||||
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
|
||||
|
||||
+57
-17
@@ -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
|
||||
@@ -83,3 +107,19 @@ class Nfdc(object):
|
||||
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
|
||||
Reference in new issue
Block a user