Reputation: 31
I have to work on Mininet, Python, SDN and my objective is to do a simple task: create a network with some switches connected randomly (so the topology is not important), every one with a host connected. In the network I have to do load balancing and I have to be able to monitor if the load balancing is working.
This is a project and so the load balancing has to be simple and it has to something like this: H1 wants to ping H2 and from H1 to H2 there exactly 2 paths with the same number of hops (for example H1 connected so S1 and H2 connected to S2. Then S1 is connected to S3 and S4, that are also connected to S2). The two paths are: H1-S1-S3-S2-H2 and H1-S1-S4-S2-H2. I want to do load balancing in a way that if H1 sends 2 ping, 1 goes throws the first path and the second one goes to the second path. In this way when H1 sends some traffic to H2, the traffic goes 50% on the first path and 50% on the second.
How can I implement something like this in a really simple network (4 switches like in the example)? I've searched a lot for some references but I've found nothing useful. In theory I have to use NOX, but if I have to use POX to understand the topic I'll do it ;)
Thanks in advice to everyone who will try to help me :)
Upvotes: 2
Views: 1630
Reputation: 1
this is a simple way to do it:
loadBalancingTopology.py:
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.link import TCLink
class LoadBalancingTopology(Topo):
def build(self):
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')
self.addLink(h1, s1)
self.addLink(h2, s1)
self.addLink(h3, s2)
self.addLink(h4,s2)
topo = LoadBalancingTopology()
net = Mininet(topo=topo, link=TCLink, controller=RemoteController)
net.start()
and the load_balancer_controller.py
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import ethernet
class LoadBalancerController(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(LoadBalancerController, self).__init__(*args, **kwargs)
self.datapaths = {}
@set_ev_cls(ofp_event.EventOFPStateChange, [CONFIG_DISPATCHER, MAIN_DISPATCHER])
def _state_change_handler(self, ev):
datapath = ev.msg.datapath
if ev.state == MAIN_DISPATCHER:
self.datapaths[datapath.id] = datapath
self.logger.info("Switch %s is connected", datapath.id)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
pkt = ethernet.ethernet(raw=msg.data)
eth_dst = pkt.dst
eth_src = pkt.src
if datapath.id == 1:
out_port = ofproto.OFPP_PORT
else:
out_port = 1
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
data = None if msg.buffer_id == ofproto.OFP_NO_BUFFER else msg.data
out = datapath.ofproto_parser.OFPPacketOut(
datapath = datapath,
buffer_id = msg.buffer_id,
in_port=msg.match['in_port'],
actions = actions,
data = data
)
datapath.senf_msg(out)
Upvotes: 0
Reputation: 679
I know you can load balance the connections between switch and controllers but not sure about the switch-switch paths .
Apparently, in openflow a type of group called "select groups". I think based on the wigth assigned to that buckets you can distribute packets. The bucket’s share of the traffic processed by the group is defined by the individual bucket’s weight divided by the sum of the bucket weights in the group. I'm not totally sure about this though.
There are ways around it too. You could set it so that a host is receiving packets from one of the paths and sending packets from the other one.
Another trick could be distributing loads based on packet protocols or other factors. For example you could say send all TCP packets from this path and all UDP packets from different path.
Upvotes: 0