I have created a simple triangle topology by using sflow.py script shipping with sflow/extras file to learn the functionality of sflow agents on OpenFlow switches.I have a remote sFLow-RT collector running on 192.168.1.103:8008.I expect to see 3 sflow agents installed on each switch on my triangle network. Mininet console also says that sflow is enabled on switches.However, sflow dashboard does not see these installed agents. I am aware of automatically installation of sflow agents with sflow.py script When I install it manually with the below script,I observe that only one sflow agent is installed on one of there switches.I also tried giving different IP addresses and port number while installing manually. However, my observed dashboard result for number of agents is still 1. What can I do for ensuring different agents installed on my each switch.
My python script is specified below.
-------------------------------------------------------------------------------------------------------------------------------
from mininet.topo import Topo
from
mininet.net import Mininet
from mininet.log import setLogLevel
from mininet.cli import CLI
from mininet.node import RemoteController
from time import sleep
from mininet.link import Intf
from
mininet.net import Mininet
from mininet.util import quietRun
from requests import put
from json import dumps
from os import listdir, environ
import re
import socket
import fcntl
import array
import struct
import sys
NODE1_IP = "192.168.1.103"
collector = environ.get('COLLECTOR','192.168.1.103')
sampling = environ.get('SAMPLING','10')
polling = environ.get('POLLING','10')
def getIfInfo(dst):
is_64bits = sys.maxsize > 2**32
struct_size = 40 if is_64bits else 32
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
max_possible = 8 # initial value
while True:
bytes = max_possible * struct_size
names = array.array('B')
for i in range(0, bytes):
names.append(0)
outbytes = struct.unpack('iL', fcntl.ioctl(
s.fileno(),
0x8912, # SIOCGIFCONF
struct.pack('iL', bytes, names.buffer_info()[0])
))[0]
if outbytes == bytes:
max_possible *= 2
else:
break
namestr = names.tostring()
s.connect((dst, 0))
ip = s.getsockname()[0]
for i in range(0, outbytes, struct_size):
name = namestr[i:i+16].split('\0', 1)[0]
addr = socket.inet_ntoa(namestr[i+20:i+24])
if addr == ip:
return (name,addr)
def configSFlow(net,collector,ifname,sampling,polling):
print "*** Enabling sFlow:"
sflow = 'ovs-vsctl -- --id=@sflow create sflow agent=%s target=%s sampling=%s polling=%s --' % (ifname,collector,sampling,polling)
for s in net.switches:
sflow += ' -- set bridge %s sflow=@sflow' % s
print ' '.join([
s.name for s in net.switches])
quietRun(sflow)
def sendTopology(net,agent,collector):
print "*** Sending topology"
topo = {'nodes':{}, 'links':{}}
for s in net.switches:
topo['nodes'][
s.name] = {'agent':agent, 'ports':{}}
path = '/sys/devices/virtual/net/'
for child in listdir(path):
parts = re.match('(^.+)-(.+)', child)
if parts == None: continue
if parts.group(1) in topo['nodes']:
ifindex = open(path+child+'/ifindex').read().split('\n',1)[0]
topo['nodes'][parts.group(1)]['ports'][child] = {'ifindex': ifindex}
i = 0
for s1 in net.switches:
j = 0
for s2 in net.switches:
if j > i:
intfs = s1.connectionsTo(s2)
for intf in intfs:
s1ifIdx = topo['nodes'][
s1.name]['ports'][intf[0].name]['ifindex']
s2ifIdx = topo['nodes'][
s2.name]['ports'][intf[1].name]['ifindex']
linkName = '%s-%s' % (
s1.name,
s2.name)
topo['links'][linkName] = {'node1':
s1.name, 'port1': intf[0].name, 'node2':
s2.name, 'port2': intf[1].name}
j += 1
i += 1
put('http://'+collector+':8008/topology/json',data=dumps(topo))
class MyTopo( Topo ):
"Simple topology example."
def build( self ):
S1 = self.addSwitch('s1')
S2 = self.addSwitch('s2')
S3 = self.addSwitch('s3')
H1 = self.addHost('h1')
H2 = self.addHost('h2')
H3 = self.addHost('h3')
self.addLink(S1,S2)
self.addLink(S1,S3)
self.addLink(S2,S3)
self.addLink(H1,S1)
self.addLink(H2,S2)
self.addLink(H3,S3)
if __name__ == '__main__':
setLogLevel('info')
topo = MyTopo()
#change the controller IP?
c1 = RemoteController('c1', ip=NODE1_IP)
net = Mininet(topo=topo, controller=c1)
(ifname, agent) = getIfInfo(collector)
configSFlow(net,collector,ifname,sampling,polling)
sendTopology(net,agent,collector)
net.start()
sleep(5)
net.pingAll()
CLI(net)
net.stop()
Topology is created successfully.
sflow is enabled on s1 s2 s3.But I can not see that it is enabled.
Dashboard says that number of Agents equals to 0.