This allows setting up static routing in large topologies in a reasonable time. Some timer values are also reduced, seems to work fine to me Change-Id: I112cfd216615a100db6dc18182db40ba614d83e6
127 lines
5.0 KiB
Python
127 lines
5.0 KiB
Python
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
|
#
|
|
# Copyright (C) 2015-2020, The University of Memphis,
|
|
# Arizona Board of Regents,
|
|
# Regents of the University of California.
|
|
#
|
|
# This file is part of Mini-NDN.
|
|
# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
|
|
#
|
|
# Mini-NDN is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Mini-NDN is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Mini-NDN, e.g., in COPYING.md file.
|
|
# If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from mininet.log import debug
|
|
from minindn.minindn import Minindn
|
|
|
|
# If needed (e.g. to speed up the process), use a smaller (or larger value)
|
|
# based on your machines resource (CPU, memory)
|
|
SLEEP_TIME = 0.1
|
|
|
|
class Nfdc(object):
|
|
STRATEGY_ASF = 'asf'
|
|
STRATEGY_BEST_ROUTE = 'best-route'
|
|
STRATEGY_MULTICAST = 'multicast'
|
|
STRATEGY_NCC = 'ncc'
|
|
PROTOCOL_UDP = 'udp'
|
|
PROTOCOL_TCP = 'tcp'
|
|
PROTOCOL_ETHER = 'ether'
|
|
|
|
@staticmethod
|
|
def registerRoute(node, namePrefix, remoteNode, protocol=PROTOCOL_UDP, origin=255,
|
|
cost=0, inheritFlag=True, captureFlag=False, expirationInMillis=None):
|
|
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, 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, allowExisting=True):
|
|
'''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'
|
|
))
|
|
output = node.cmd(cmd)
|
|
debug(output)
|
|
Minindn.sleep(SLEEP_TIME)
|
|
if "face-created" in output or (allowExisting and "face-exists" in output):
|
|
faceID = output.split(" ")[1][3:]
|
|
return faceID
|
|
return -1
|
|
|
|
@staticmethod
|
|
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
|
|
def setStrategy(node, namePrefix, strategy):
|
|
cmd = 'nfdc strategy set {} ndn:/localhost/nfd/strategy/{}'.format(namePrefix, strategy)
|
|
debug(node.cmd(cmd))
|
|
Minindn.sleep(SLEEP_TIME)
|
|
|
|
@staticmethod
|
|
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 |