[环境搭建]SDN网络感知服务与最短路径应用

Posted hallowC

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[环境搭建]SDN网络感知服务与最短路径应用相关的知识,希望对你有一定的参考价值。

  • 1.安装python模块networkx

pip install networkx

Image(49)

  • 2.给Network_Awareness.py加修改权限

chmod 777 Network_Awareness.py

  • 3.下载安装ryu

git clone git://github.com/osrg/ryu.git

cd ryu sudo python

./setup.py install

#若已安装ryu,删了再装, pip uninstall ryu

  • 4.修改“***/ryu/ryu/flags.py"文件,在实例“CONF”调用的方法“register_cli_opts”的字典里添加:

CONF.register_cli_opts([

# k_shortest_forwarding

cfg.IntOpt(\'k-paths\', default=1, help=\'number for k shortest paths\'),

cfg.StrOpt(\'weight\', default=\'hop\',

help=\'weight type of computing shortest path.\')])

如图:

  • Image(50)

  • 5.修改文件"/ryu/ryu/topology/switches.py",在“PortData”类的初始化方法中添加了实例变量“self.delay”:

self.delay = 0

Image(51)

  • 在“@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)”下添加:

def packet_in_handler(self, ev):

# add code for getting LLDP packet receiving timestamp

recv_timestamp = time.time()

if not self.link_discovery:

return

msg = ev.msg

try:

src_dpid, src_port_no = LLDPPacket.lldp_parse(msg.data)

except LLDPPacket.LLDPUnknownFormat as e:

# This handler can receive all the packtes which can be

# not-LLDP packet. Ignore it silently

return

dst_dpid = msg.datapath.id

if msg.datapath.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:

dst_port_no = msg.in_port

elif msg.datapath.ofproto.OFP_VERSION >= ofproto_v1_2.OFP_VERSION:

dst_port_no = msg.match[\'in_port\']

else:

LOG.error(\'cannot accept LLDP. unsupported version. %x\',

msg.datapath.ofproto.OFP_VERSION)

# get the lldp delay, and save it into port_data.

for port in self.ports.keys():

if src_dpid == port.dpid and src_port_no == port.port_no:

send_timestamp = self.ports[port].timestamp

if send_timestamp:

self.ports[port].delay = recv_timestamp - send_timestamp

    • Image(52)

  • 6.重新编译安装ryu

cd ***/ryu

python setup.py install

  • 7.启动ryu控制器

ryu-manager shortest_forwarding.py --observe-links --k-paths=2 --weight=bw

  • 8.开启mininet并连接控制器

mn --controller=remote,ip=192.168.1.197,port=6653

注:“ip”填写的是启动ryu控制器的那台主机的ip

以上是关于[环境搭建]SDN网络感知服务与最短路径应用的主要内容,如果未能解决你的问题,请参考以下文章

勾股定理与最短路径问题

[平面几何]轴对称与最短路径问题

破圈法求最小生成树+最小生成树与最短路径问题

线性规划问题中的差分约束与最短路径

图 - 最短路径 (二)

让网络理政成为疏导民意的最短路径