Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About my confusion about ip-routing demo #1

Open
VulnDetector opened this issue Nov 2, 2021 · 0 comments
Open

About my confusion about ip-routing demo #1

VulnDetector opened this issue Nov 2, 2021 · 0 comments

Comments

@VulnDetector
Copy link

VulnDetector commented Nov 2, 2021

Much thanks for reading this.I'm really looking forward to your reply!
I'm trying to learn p4 program,and I suppose I understand the basic things of p4. When I analyze your ip-routing in p4-demo,I can understand the p4 program,but I don't quite understand the topo.py,that is,why sw_path or json_path is needed,or what does this mean?

s1 = self.addSwitch('s1',
                            sw_path=sw_path,
                            json_path=json_path,
                            thrift_port=9090)
s2 = self.addSwitch('s2',
                            sw_path=sw_path,
                            json_path=json_path,
                            thrift_port=9091)
 s3 = self.addSwitch('s3',
                            sw_path=sw_path,
                            json_path=json_path,
                            thrift_port=9092)

so I change the program,without the sw_path,json_path in the addSwitch:

import sys
sys.path.append('../')
sys.path.append('/home/p4/tutorials/utils')
from p4_mininet import P4Switch, P4Host
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import setLogLevel, info
from mininet.cli import CLI

import argparse



class DemoTopo(Topo):
    "Demo topology"

    def __init__(self,**opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

        s1 = self.addSwitch('s1',
                            thrift_port=9090)
        s2 = self.addSwitch('s2',
                            thrift_port=9091)
        s3 = self.addSwitch('s3',
                            thrift_port=9092)

        h1 = self.addHost('h1',
                            ip="10.0.10.10/24",
                            mac='00:00:00:00:00:01')
        h2 = self.addHost('h2',
                          ip="10.0.20.10/24",
                          mac='00:00:00:00:00:02')
        h3 = self.addHost('h3',
                          ip="10.0.30.10/24",
                          mac='00:00:00:00:00:03')

        self.addLink(s1, h1)
        self.addLink(s2, h2)
        self.addLink(s3, h3)

        self.addLink(s1, s2)
        self.addLink(s2, s3)
        self.addLink(s1, s3)


def main():
    topo = DemoTopo()

    net = Mininet(topo=topo,
                  host=P4Host,
                  switch=P4Switch,
                  controller=None)
    net.start()

    s1 = net.get('s1')
    s1.setIP('10.0.10.1/24', intf = 's1-eth1')
    s1.setMAC('00:00:00:00:01:01', intf = 's1-eth1')
    s1.setIP('192.168.1.1/24', intf = 's1-eth2')
    s1.setMAC('00:00:00:00:01:02', intf='s1-eth2')
    s1.setIP('192.168.3.254/254', intf = 's1-eth3')
    s1.setMAC('00:00:00:00:01:03', intf='s1-eth3')

    s2 = net.get('s2')
    s2.setIP('10.0.20.1/24', intf = 's2-eth1')
    s2.setMAC('00:00:00:00:02:01', intf='s2-eth1')
    s2.setIP('192.168.3.1/24', intf = 's2-eth2')
    s2.setMAC('00:00:00:00:02:02', intf='s2-eth2')
    s2.setIP('192.168.2.254/24', intf = 's2-eth3')
    s2.setMAC('00:00:00:00:02:03', intf='s2-eth3')

    s3 = net.get('s3')
    s3.setIP('10.0.30.1/24', intf='s3-eth1')
    s3.setMAC('00:00:00:00:03:01', intf='s3-eth1')
    s3.setIP('192.168.2.1', intf='s3-eth2')
    s3.setMAC('00:00:00:00:03:02', intf='s3-eth2')
    s3.setIP('192.168.1.254/24', intf='s3-eth3')
    s3.setMAC('00:00:00:00:03:03', intf='s3-eth3')

    h1 = net.get('h1')
    h1.setDefaultRoute("dev eth0 via 10.0.10.1")

    h2 = net.get('h2')
    h2.setDefaultRoute("dev eth0 via 10.0.20.1")

    h3 = net.get('h3')
    h3.setDefaultRoute("dev eth0 via 10.0.30.1")

    print("Ready !")

    CLI(net)

    net.stop()

if __name__ == '__main__':
    setLogLevel('info')
    main()

But when I run the code,the compiler told me this:
image

In fact,I just want to implement the ip routing in p4,and I want to specify the ip address for the p4 switch.Therefore,I have such confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant