
from mininet.topo import Topo, Node

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self, enable_all = True ):
        "Create custom topo."

        # Add default members to class.
        super( MyTopo, self ).__init__()

        # Set Node IDs for hosts and switches
        leftHost = 1
        leftSwitch = 2
        rightSwitch = 3
        rightHost = 4

        # Add nodes
        self.addNode( leftSwitch, Node( isSwitch=True ) )
        self.addNode( rightSwitch, Node( isSwitch=True ) )
        self.addNode( leftHost, Node( isSwitch=False ) )
        self.addNode( rightHost, Node( isSwitch=False ) )

        # Add edges
        self.add_edge( leftHost, leftSwitch )
        self.add_edge( leftSwitch, rightSwitch )
        self.add_edge( rightSwitch, rightHost )

        # Consider all switches and hosts 'on'
        self.enable_all()


topos = { 'mytopo': ( lambda: MyTopo() ) }


from mininet.topo import Topo
from mininet.node import Node

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self, enable_all = True ):
        "Create custom topo."

        # Add default members to class.
        super( MyTopo, self ).__init__()

        # Set Node IDs for hosts and switches
        leftHost = 1
        leftSwitch = 2
        rightSwitch = 3
        rightHost = 4

        # Add nodes
        self.addNode( leftSwitch, Node( isSwitch=True ) )
        self.addNode( rightSwitch, Node( isSwitch=True ) )
        self.addNode( leftHost, Node( isSwitch=False ) )
        self.addNode( rightHost, Node( isSwitch=False ) )

        # Add edges
        self.add_edge( leftHost, leftSwitch )
        self.add_edge( leftSwitch, rightSwitch )
        self.add_edge( rightSwitch, rightHost )

        # Consider all switches and hosts 'on'
        self.enable_all()


topos = { 'mytopo': ( lambda: MyTopo() ) }

Fix custom topology example; outdated import
Fix custom topology example; outdated import

Reported-by: Julius Bachnick

  
- from mininet.topo import Topo, Node
+ from mininet.topo import Topo
+ from mininet.node import Node
  
  class MyTopo( Topo ):
      "Simple topology example."
  
      def __init__( self, enable_all = True ):
          "Create custom topo."
  
          # Add default members to class.
          super( MyTopo, self ).__init__()
  
          # Set Node IDs for hosts and switches
          leftHost = 1
          leftSwitch = 2
          rightSwitch = 3
          rightHost = 4
  
          # Add nodes
          self.addNode( leftSwitch, Node( isSwitch=True ) )
          self.addNode( rightSwitch, Node( isSwitch=True ) )
          self.addNode( leftHost, Node( isSwitch=False ) )
          self.addNode( rightHost, Node( isSwitch=False ) )
  
          # Add edges
          self.add_edge( leftHost, leftSwitch )
          self.add_edge( leftSwitch, rightSwitch )
          self.add_edge( rightSwitch, rightHost )
  
          # Consider all switches and hosts 'on'
          self.enable_all()
  
  
  topos = { 'mytopo': ( lambda: MyTopo() ) }
  
Fix custom topology example; outdated import
## Code Before:

from mininet.topo import Topo, Node

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self, enable_all = True ):
        "Create custom topo."

        # Add default members to class.
        super( MyTopo, self ).__init__()

        # Set Node IDs for hosts and switches
        leftHost = 1
        leftSwitch = 2
        rightSwitch = 3
        rightHost = 4

        # Add nodes
        self.addNode( leftSwitch, Node( isSwitch=True ) )
        self.addNode( rightSwitch, Node( isSwitch=True ) )
        self.addNode( leftHost, Node( isSwitch=False ) )
        self.addNode( rightHost, Node( isSwitch=False ) )

        # Add edges
        self.add_edge( leftHost, leftSwitch )
        self.add_edge( leftSwitch, rightSwitch )
        self.add_edge( rightSwitch, rightHost )

        # Consider all switches and hosts 'on'
        self.enable_all()


topos = { 'mytopo': ( lambda: MyTopo() ) }

## Instruction:
Fix custom topology example; outdated import
## Code After:

from mininet.topo import Topo
from mininet.node import Node

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self, enable_all = True ):
        "Create custom topo."

        # Add default members to class.
        super( MyTopo, self ).__init__()

        # Set Node IDs for hosts and switches
        leftHost = 1
        leftSwitch = 2
        rightSwitch = 3
        rightHost = 4

        # Add nodes
        self.addNode( leftSwitch, Node( isSwitch=True ) )
        self.addNode( rightSwitch, Node( isSwitch=True ) )
        self.addNode( leftHost, Node( isSwitch=False ) )
        self.addNode( rightHost, Node( isSwitch=False ) )

        # Add edges
        self.add_edge( leftHost, leftSwitch )
        self.add_edge( leftSwitch, rightSwitch )
        self.add_edge( rightSwitch, rightHost )

        # Consider all switches and hosts 'on'
        self.enable_all()


topos = { 'mytopo': ( lambda: MyTopo() ) }
