Hello Ryuians,
I am trying to make an application to push shortest path flows to the switches.
In my mininet topology I specifically mentioned the MAC addresses for each
switch port. When I check the MAC addresses from mininet terminal it shows the
MAC addresses I configured in the topology. But when I run the application,
packet_in occurs from a lot of unknown MAC addresses which are not even in my
topology. So its getting too difficult for me to debug the application because
of these unknown MACs.
I am not actually sure from where these MACs are coming from. Can anyone help?
Also how can I push hard coded flows to the switches at the beginning of the
application run(from the application not using Curl)? My intention to try this,
is to avoid flooding packet when destination is unknown.
I attached the application with this email. I will be grateful if someone can
help me with this.
RegardsSakib
# This is part of our final project for the Computer Networks Graduate Course
at Georgia Tech
# You can take the official course online too! Just google CS 6250 online at
Georgia Tech.
#
# Contributors:
#
# Akshar Rawal ([email protected])
# Flavio Castro ([email protected])
# Logan Blyth ([email protected])
# Matthew Hicks ([email protected])
# Uy Nguyen ([email protected])
#
# To run:
#
# ryu--manager --observe-links shortestpath.py
#
#Copyright (C) 2014, Georgia Institute of Technology.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
An OpenFlow 1.0 shortest path forwarding implementation.
"""
import logging
import struct
from ryu.base import app_manager
from ryu.controller import mac_to_port
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.topology.api import get_switch, get_link
from ryu.app.wsgi import ControllerBase
from ryu.topology import event, switches
import networkx as nx
class ProjectController(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(ProjectController, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self.topology_api_app = self
self.net=nx.DiGraph()
self.nodes = {}
self.links = {}
self.no_of_nodes = 0
self.no_of_links = 0
self.i=0
def add_flow(self, datapath, in_port, dst, actions):
ofproto = datapath.ofproto
match = datapath.ofproto_parser.OFPMatch(
in_port=in_port, dl_dst=haddr_to_bin(dst))
mod = datapath.ofproto_parser.OFPFlowMod(
datapath=datapath, match=match, cookie=0,
command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
priority=ofproto.OFP_DEFAULT_PRIORITY,
flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
datapath.send_msg(mod)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
dst = eth.dst
src = eth.src
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
# out_port = None
if len(str(src)) > 2:
print
"######################################################################################################################"
print "Nodes : ", self.net.nodes()
print "Edges : ", self.net.edges()
print
"**********************************************************************************************************************"
self.logger.info("packet in %s %s %s %s", dpid, src, dst, msg.in_port)
# learn mac address to avoid FLOOD next time
self.mac_to_port[dpid][src] = msg.in_port
source_list = ["0A:00:01:01:00:00", "0A:00:02:02:00:00",
"0A:00:03:03:00:00", "0A:00:04:04:00:00",
"0A:00:05:05:00:00", "0A:00:06:06:00:00",
"0A:00:07:07:00:00"]
if str(src) in source_list:
#if {'port':msg.in_port} not in self.net[dpid].values():
self.net.add_node(src)
self.net.add_edge(dpid,src,{'port':msg.in_port})
self.net.add_edge(src,dpid)
if dst in self.net.nodes():
print
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
print "Destination is in self.net"
#print "Source, Destination", src, dst
#print self.net.nodes()
path=nx.shortest_path(self.net,src,dst)
print "path :", path
#print "DPID", dpid
next=path[path.index(dpid)+1]
print "next :", next
print "port :", self.net[dpid][next]
out_port=self.net[dpid][next]['port']
else:
out_port = ofproto.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, msg.in_port, dst, actions)
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions)
datapath.send_msg(out)
@set_ev_cls(event.EventSwitchEnter)
def get_topology_data(self, ev):
switch_list = get_switch(self.topology_api_app, None)
switches=[switch.dp.id for switch in switch_list]
self.net.add_nodes_from(switches)
links_list = get_link(self.topology_api_app, None)
#print "link list",links_list
links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link
in links_list]
#print links
self.net.add_edges_from(links)
links=[(link.dst.dpid,link.src.dpid,{'port':link.dst.port_no}) for link
in links_list]
#print links
self.net.add_edges_from(links)
node_num = len(self.net.nodes())
self.i += 1
if self.i > 5:
for i in range(node_num):
print str(self.net.nodes()[i])+ "'s connections :",
self.net[self.net.nodes()[i]]
#print "Edges to inspect port_no", self.net[]
#print "**********List of links"
#print self.net.nodes()
#for link in links_list:
#print link.dst
#print link.src
#print "Novo link"
#self.no_of_links += 1
#print "@@@@@@@@@@@@@@@@@Printing both arrays@@@@@@@@@@@@@@@"
#for node in self.nodes:
# print self.nodes[node]
#for link in self.links:
# print self.links[link]
#print self.no_of_nodes
#print self.no_of_links
#@set_ev_cls(event.EventLinkAdd)
#def get_links(self, ev):
#print "################Something##############"
#print ev.link.src, ev.link.dst------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel