'How to expose docker images as containernet hosts in ONOS GUI?

I am trying to run the containernet_example.py file (where I modified the 2 docker image hosts with my docker images) with ONOS as the controller for my topology.

When I accessed the ONOS UI page via localhost:8181/onos/ui/login.html I was not able to access the hosts, i.e. docker images in the UI page. I mean the topology is not displayed in the onos page but in the containernet CLI, the ping works for the hosts. The command I use is:

sudo mn --controller remote,ip=MYIPADDRESS --switch=ovsk,protocols=OpenFlow13 --custom containernet_example.py

Whereas if I try standard topologies like tree, I am able to access those topologies. I want to use those docker images as hosts in onos gui and as well as in containernet cli.

I have been reading so many posts but I could not solve this issue. Any insight would be helpful. Thanks in advance.



Solution 1:[1]

The code used for this has been acquired from another StackOverflow link, which I could not tag as I could not bookmark the page exactly. Below is the code that worked for me in the case of 2 docker images as containernet hosts.

from mininet.net import Containernet
from mininet.node import Controller, OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
setLogLevel('info')
net = Containernet(controller=RemoteController, switch=OVSKernelSwitch) #remote controller
info('*** Adding controller\n')
net.addController('c0', controller=RemoteController, ip= 'MYIPADDRESS', port= 6653)
info('*** Adding docker containers\n')
d1 = net.addDocker('d1', ip='10.0.0.251', dimage="myimage1:myimagetag")
d2 = net.addDocker('d2', ip='10.0.0.252', dimage="myimage2:myimagetag")
info('*** Adding switches\n')
s1 = net.addSwitch('s1', protocols= "OpenFlow13") #mentioning protocol


info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(d2, s1)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d1, d2,])
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()

And the command I used is simple sudo python3 myfilename.py

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Newuser5