sdn第三次作业

SDN第三次实验报告

(一)基本要求

1.拓扑文件的存放:

拓扑文件(导出为Python):

#!/usr/bin/env python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call


def myNetwork():
    net = Mininet(topo=None,
                  build=False,
                  ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=Controller,
                           protocol='tcp',
                           port=6633)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)


    info('*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='192.168.0.101/24', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='192.168.0.102/24', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='192.168.0.103/24', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='192.168.0.104/24', defaultRoute=None)

    info('*** Add links\n')
    net.addLink(h1, s1, 1, 1)
    net.addLink(h2, s1, 1, 2)
    net.addLink(h3, s2, 1, 1)
    net.addLink(h4, s2, 1, 2)
    net.addLink(s1, s2, 3, 3)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0])
    net.get('s2').start([c0])


    info('*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()


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

抓包:

hello 控制器6633端口--->交换机48056端口

交换机48056端口 ---控制器6633端口(支持Openflow1.5)

Fertures Request /Set Config

Features Reply

Packet_in

Flow_MOD

PACKET_OUT

交互图

3.TCP协议

(二)进阶

数据类型采用枚举类型存储

hello

hello只用了一个ofp_header的结构存储。

数据头。

struct ofp_header {
    uint8_t version;    /* OFP版本. */
    uint8_t type;       /* 数据包类型 */
    uint16_t length;    /* 长度 */
    uint32_t xid;       /* 用于将请求指令和相应指令相对应*/

features_request

struct ofp_switch_features {
    struct ofp_header header;
    uint64_t datapath_id;   /* 数据路径唯一ID。较低的48位用于MAC地址,而上面的16位是实现者定义。 */

    uint32_t n_buffers;     /* 一次缓冲的最大数据包数。 */

    uint8_t n_tables;       /* 数据路径支持的表数。 */
    uint8_t pad[3];         /* 对齐到64位 */

    /* Features. */
    uint32_t capabilities;  /* Bitmap of support "ofp_capabilities". */
    uint32_t actions;       /* Bitmap of supported "ofp_action_type"s. */

    /* Port info.*/
    struct ofp_phy_port ports[0];  /* 端口定义。端口数从中的“长度”字段推断标题。 */
};

set config

packet_in

flow_mod

struct ofp_flow_mod {
    struct ofp_header header;
    struct ofp_match match;      /* 要匹配的字段 */
    uint64_t cookie;             /* 控制器问题标识符 */

    /* Flow actions. */
    uint16_t command;             /* One of OFPFC_*. */
    uint16_t idle_timeout;        /* Idle time before discarding (seconds). */
    uint16_t hard_timeout;        /* Max time before discarding (seconds). */
    uint16_t priority;            /* 优先度 */
    uint32_t buffer_id;           /* Buffered packet to apply to (or -1).
                                     Not meaningful for OFPFC_DELETE*. */
    uint16_t out_port;            /* For OFPFC_DELETE* commands, require
                                     matching entries to include this as an
                                     output port.  A value of OFPP_NONE
                                     indicates no restriction. */
    uint16_t flags;               /* One of OFPFF_*. */
    struct ofp_action_header actions[0]; /* The action length is inferred
                                            from the length field in the
                                            header. */
};

packet_out

总结:

本次实验体验了抓包和看各种数据type,思维部分较少所以没什么可说的。第三题的TCP协议是上课就提到的,打开抓包也能看到一堆TCP报文。

值得注意的问题是Hello报文是拓扑搭建的时候就发了,需要先抓包,再建立拓扑图,才能抓到Hello。

我miniedit的pingall命令还是用不了。原来是只有我有这个问题。导出成py文件就能正常ping通。

本次实验报告讲的有点啰嗦。进阶的数据类型似乎pdf都有,打开头文件拷贝之。一时不知道写啥所以全写了。

最大体会是这门课实验容易咚咚撞大墙,如果有人一起讨论如何解决困难,会变得有趣起来。反之就是闷头苦干久久不明白原理。

posted @ 2021-09-14 21:03  张牧歌  阅读(114)  评论(0编辑  收藏  举报