Node

1. Node是什麼?

  • 每個Host其實就是一個Node的物件,可以在node.py中看到此物件的定義

node.py

class Node( object ):
    portBase = 0  # Nodes always start with eth0/port0, even in OF 1.0

    def __init__( self, name, inNamespace=True, **params ):
        self.checkSetup()

        self.name = params.get( 'name', name )
        self.privateDirs = params.get( 'privateDirs', [] )
        self.inNamespace = params.get( 'inNamespace', inNamespace )

        ...

        # Start command interpreter shell
        self.startShell()
        self.mountPrivateDirs()

    inToNode = {}  # mapping of input fds to nodes
    outToNode = {}  # mapping of output fds to nodes
  • 初始時,會有一個變數inNamespace用來決定此Host是否要透過network namespaces來達到network isolation的功能

  • 當變數都初始化後,就會呼叫startShell()來啟動此Host

node.py

def startShell( self, mnopts=None ):
    "Start a shell process for running commands"
    if self.shell:
        error( "%s: shell is already running\n" % self.name )
        return
    # mnexec: (c)lose descriptors, (d)etach from tty,
    # (p)rint pid, and run in (n)amespace
    opts = '-cd' if mnopts is None else mnopts
    if self.inNamespace:
        opts += 'n'
    # bash -i: force interactive
    # -s: pass $* to shell, and make process easy to find in ps
    # prompt is set to sentinel chr( 127 )
    cmd = [ 'mnexec', opts, 'env', 'PS1=' + chr( 127 ),
            'bash', '--norc', '-is', 'mininet:' + self.name ]

    master, slave = pty.openpty()
    self.shell = self._popen( cmd, stdin=slave, stdout=slave,stderr=slave,close_fds=False )
    ...
  • 可以觀察到,mininet是透過一隻叫做mnexec的程式來執行,並且透過參數-n來將此process給轉換到network namespaces

2. 所以建立完Host以後,可以使用ip來看?

  • 理論上我們要可以透過ip netns show來看到這些network namespaces,實際上卻看不到
    • 原因如同此篇所說,由於建立的為nameless network namespaces

3. Host是Node,那Switch呢?

  • 建立Switch包含了四種選擇OVSLegacyKernelSwitchUserSwitchOVSSwitchIVSSwitch

  • 一般常用的就是OVSSwitch

  • 這四種Switch都繼承自Switch物件,而Switch物件則繼承自Node

© 2017 Trashman all right reserved,powered by Gitbook修訂時間: 2024-10-14 03:41:00

results matching ""

    No results matching ""