예제 #1
0
    def do_install_all_controller_bound_flows(self, line):
        """
        Install all flow rules for controller bound flows, including EAPOL,
        IGMP and DHCP. If device is not given, it will be applied to logical
        device of the last pre-provisioned OLT device.
        """
        logical_device_id = line or self.default_logical_device_id

        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports(logical_device_id)

        # construct and push flow rules
        stub = self.get_stub()

        for uni_port_no, _ in unis:
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=2000,
                    match_fields=[
                        in_port(uni_port_no),
                        eth_type(0x888e)
                    ],
                    actions=[output(ofp.OFPP_CONTROLLER)]
                )
            ))
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    match_fields=[
                        in_port(uni_port_no),
                        eth_type(0x800),
                        ip_proto(2)
                    ],
                    actions=[output(ofp.OFPP_CONTROLLER)]
                )
            ))
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    match_fields=[
                        in_port(uni_port_no),
                        eth_type(0x800),
                        ip_proto(17),
                        udp_dst(67)
                    ],
                    actions=[output(ofp.OFPP_CONTROLLER)]
                )
            ))
        self.poutput('success')
예제 #2
0
    def do_install_dhcp_flows(self, line):
        """
        Install all dhcp flows that are representative of the virtualized access
        scenario in a PON network.
        """
        logical_device_id = line or self.default_logical_device_id

        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports(logical_device_id)

        # construct and push flow rules
        stub = self.get_stub()

        # Controller-bound flows
        for uni_port_no, _ in unis:
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    match_fields=[
                        in_port(uni_port_no),
                        eth_type(0x800),
                        ip_proto(17),
                        udp_dst(67)
                    ],
                    actions=[output(ofp.OFPP_CONTROLLER)]
                )
            ))

        self.poutput('success')
예제 #3
0
    def do_install_eapol_flow(self, line):
        """
        Install an EAPOL flow on the given logical device. If device is not
        given, it will be applied to logical device of the last pre-provisioned
        OLT device.
        """
        logical_device_id = line or self.default_logical_device_id

        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports(logical_device_id)

        # construct and push flow rule
        stub = self.get_stub()
        for uni_port_no, _ in unis:
            update = FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=2000,
                    match_fields=[in_port(uni_port_no), eth_type(0x888e)],
                    actions=[
                        # push_vlan(0x8100),
                        # set_field(vlan_vid(4096 + 4000)),
                        output(ofp.OFPP_CONTROLLER)
                    ]
                )
            )
            res = stub.UpdateLogicalDeviceFlowTable(update)
            self.poutput('success for uni {} ({})'.format(uni_port_no, res))
예제 #4
0
 def do_delete_all_flows(self, line):
     """
     Remove all flows and flow groups from given logical device
     """
     logical_device_id = line or self.default_logical_device_id
     stub = self.get_stub()
     stub.UpdateLogicalDeviceFlowTable(
         FlowTableUpdate(id=logical_device_id,
                         flow_mod=ofp.ofp_flow_mod(command=ofp.OFPFC_DELETE,
                                                   table_id=ofp.OFPTT_ALL,
                                                   cookie_mask=0,
                                                   out_port=ofp.OFPP_ANY,
                                                   out_group=ofp.OFPG_ANY)))
     stub.UpdateLogicalDeviceFlowGroupTable(
         FlowGroupTableUpdate(id=logical_device_id,
                              group_mod=ofp.ofp_group_mod(
                                  command=ofp.OFPGC_DELETE,
                                  group_id=ofp.OFPG_ALL)))
     self.poutput('success')
예제 #5
0
    def do_install_tf_flows(self, line, opts):
        """
        Install flows for a specific ONU
        """

        usage = '   usage: install_tf_flows -o <ONU-ID> -s <s-vid> -c <c-vid> [logical-device-id]'
        onu_id = int(opts.onu_id) if opts.onu_id is not None else None
        if onu_id is None or not (0 <= onu_id <= self.max_onu_id):
            self.poutput('Invalid ONU ID {}. Must be 0..{}'.format(onu_id, self.max_onu_id))
            self.poutput(usage)
            return

        s_vid = int(opts.s_vid) if opts.s_vid is not None else None
        if s_vid is None or not (1 <= s_vid <= 4093):
            self.poutput('Invalid S-VLAN ID {}. Must be 1..4093'.format(s_vid))
            self.poutput(usage)
            return

        c_vid = int(opts.c_vid) if opts.c_vid is not None else None
        if c_vid is None or not (1 <= s_vid <= 4093):
            self.poutput('Invalid C-VLAN ID {}. Must be 1..4093'.format(c_vid))
            self.poutput(usage)
            return

        logical_device_id = line or self.default_logical_device_id
        if logical_device_id is None:
            self.poutput('Logical Device ID not provided')
            self.poutput(usage)
            return

        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports_and_onu_ids(logical_device_id)

        # construct and push flow rules
        stub = self.get_stub()
        default_speed = self.default_speed
        found = False

        for uni_port_no, uni_onu_id in unis:
            if uni_onu_id != onu_id:
                continue

            self.poutput('Installing flows for ONU ID: {}, UNI Port:{}'.format(uni_onu_id, uni_port_no))

            # Upstream flow 1 for priority tagged case
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    match_fields=[
                        in_port(uni_port_no),
                        metadata(default_speed),
                        vlan_vid(4096 + 0)
                    ],
                    actions=[
                        set_field(vlan_vid(4096 + c_vid))
                    ],
                    next_table_id=1
                )
            ))
            # Upstream flow 2 for s-tag
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    table_id=1,
                    match_fields=[
                        in_port(uni_port_no),
                        metadata(default_speed),
                        vlan_vid(4096 + c_vid)
                    ],
                    actions=[
                        push_vlan(0x8100),
                        set_field(vlan_vid(4096 + s_vid)),
                        output(nni_port_no)
                    ]
                )
            ))
            #######################################################
            # Downstream flow 1
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    match_fields=[
                        in_port(nni_port_no),
                        metadata((default_speed << (12 + 32)) | c_vid << 32 | uni_port_no),
                        vlan_vid(4096 + s_vid),
                    ],
                    actions=[pop_vlan()],
                    next_table_id=1
                )
            ))
            # Downstream flow 2
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=1000,
                    table_id=1,
                    match_fields=[
                        in_port(nni_port_no),
                        vlan_vid(4096 + c_vid)
                    ],
                    actions=[
                        pop_vlan(),
                        output(uni_port_no)
                    ]
                )
            ))
            self.poutput('success')
            found = True

        if not found:
            self.poutput('[ERROR] ONU with ID of {} not found'.format(onu_id))
예제 #6
0
    def do_install_all_att_flows(self, line):
        """
        Install all flows that are representative of the virtualized access
        scenario in a PON network.
        """

        self.poutput('inside install sample flows')
        logical_device_id = line or self.default_logical_device_id
    
        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports(logical_device_id)
    
        self.poutput('inside for {} {} {} '.format(nni_port_no, unis, logical_device_id))
    
        # construct and push flow rules
        stub = self.get_stub()
        s_vid = 9
        c_vid = 2
    
        for uni_port_no, c_vid in unis:
            self.poutput('inside for {} {}'.format(uni_port_no, c_vid))
            # Unicast flows:
            # Downstream flow 1
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=500,
                    match_fields=[
                        in_port(nni_port_no),
                        vlan_vid(4096 + s_vid),
                        metadata(c_vid << 32 | uni_port_no)
                    ],
                    actions=[pop_vlan()],
                    next_table_id=1
                )
            ))
            # Downstream flow 2
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=500,
                    table_id=1,
                    match_fields=[in_port(nni_port_no), vlan_vid(4096 + 2)],
                    actions=[pop_vlan(), output(uni_port_no)]
                )
            ))
            # Upstream flow 1 for untagged case
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=500,
                    match_fields=[in_port(uni_port_no), vlan_vid(0)],
                    actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 2))],
                    next_table_id=1
                )
            ))
    
            # Upstream flow 2 for s-tag
            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
                id=logical_device_id,
                flow_mod=mk_simple_flow_mod(
                    priority=500,
                    table_id=1,
                    match_fields=[in_port(uni_port_no), vlan_vid(4096 + 2)],
                    actions=[
                        push_vlan(0x8100),
                        set_field(vlan_vid(4096 + s_vid)),
                        output(nni_port_no)
                    ]
                )
            ))
    
        self.poutput('success')
예제 #7
0
    def do_install_all_sample_flows(self, line):
        """
        Install all flows that are representative of the virtualized access
        scenario in a PON network.
        """
        logical_device_id = line or self.default_logical_device_id

        # gather NNI and UNI port IDs
        nni_port_no, unis = self.get_logical_ports(logical_device_id)

        # construct and push flow rules
        stub = self.get_stub()

        for uni_port_no, c_vid in unis:
            # Controller-bound flows
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(
                    id=logical_device_id,
                    flow_mod=mk_simple_flow_mod(
                        priority=2000,
                        match_fields=[in_port(uni_port_no),
                                      eth_type(0x888e)],
                        actions=[
                            # push_vlan(0x8100),
                            # set_field(vlan_vid(4096 + 4000)),
                            output(ofp.OFPP_CONTROLLER)
                        ])))
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(
                    id=logical_device_id,
                    flow_mod=mk_simple_flow_mod(
                        priority=1000,
                        match_fields=[eth_type(0x800),
                                      ip_proto(2)],
                        actions=[output(ofp.OFPP_CONTROLLER)])))
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(id=logical_device_id,
                                flow_mod=mk_simple_flow_mod(
                                    priority=1000,
                                    match_fields=[
                                        eth_type(0x800),
                                        ip_proto(17),
                                        udp_dst(67)
                                    ],
                                    actions=[output(ofp.OFPP_CONTROLLER)])))

            # Unicast flows:
            # Downstream flow 1
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(
                    id=logical_device_id,
                    flow_mod=mk_simple_flow_mod(
                        priority=500,
                        match_fields=[
                            in_port(nni_port_no),
                            vlan_vid(4096 + 1000),
                            metadata(c_vid)  # here to mimic an ONOS artifact
                        ],
                        actions=[pop_vlan()],
                        next_table_id=1)))
            # Downstream flow 2
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(id=logical_device_id,
                                flow_mod=mk_simple_flow_mod(
                                    priority=500,
                                    table_id=1,
                                    match_fields=[
                                        in_port(nni_port_no),
                                        vlan_vid(4096 + c_vid)
                                    ],
                                    actions=[
                                        set_field(vlan_vid(4096 + 0)),
                                        output(uni_port_no)
                                    ])))
            # Upstream flow 1 for 0-tagged case
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(
                    id=logical_device_id,
                    flow_mod=mk_simple_flow_mod(
                        priority=500,
                        match_fields=[
                            in_port(uni_port_no),
                            vlan_vid(4096 + 0)
                        ],
                        actions=[set_field(vlan_vid(4096 + c_vid))],
                        next_table_id=1)))
            # Upstream flow 1 for untagged case
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(
                    id=logical_device_id,
                    flow_mod=mk_simple_flow_mod(
                        priority=500,
                        match_fields=[in_port(uni_port_no),
                                      vlan_vid(0)],
                        actions=[
                            push_vlan(0x8100),
                            set_field(vlan_vid(4096 + c_vid))
                        ],
                        next_table_id=1)))
            # Upstream flow 2 for s-tag
            stub.UpdateLogicalDeviceFlowTable(
                FlowTableUpdate(id=logical_device_id,
                                flow_mod=mk_simple_flow_mod(
                                    priority=500,
                                    table_id=1,
                                    match_fields=[
                                        in_port(uni_port_no),
                                        vlan_vid(4096 + c_vid)
                                    ],
                                    actions=[
                                        push_vlan(0x8100),
                                        set_field(vlan_vid(4096 + 1000)),
                                        output(nni_port_no)
                                    ])))

        # Push a few multicast flows
        # 1st with one bucket for our uni 0
        stub.UpdateLogicalDeviceFlowGroupTable(
            FlowGroupTableUpdate(
                id=logical_device_id,
                group_mod=mk_multicast_group_mod(
                    group_id=1,
                    buckets=[
                        ofp.ofp_bucket(
                            actions=[pop_vlan(),
                                     output(unis[0][0])])
                    ])))
        stub.UpdateLogicalDeviceFlowTable(
            FlowTableUpdate(id=logical_device_id,
                            flow_mod=mk_simple_flow_mod(
                                priority=1000,
                                match_fields=[
                                    in_port(nni_port_no),
                                    eth_type(0x800),
                                    vlan_vid(4096 + 140),
                                    ipv4_dst(0xe4010101)
                                ],
                                actions=[group(1)])))

        # 2nd with one bucket for uni 0 and 1
        stub.UpdateLogicalDeviceFlowGroupTable(
            FlowGroupTableUpdate(
                id=logical_device_id,
                group_mod=mk_multicast_group_mod(
                    group_id=2,
                    buckets=[
                        ofp.ofp_bucket(
                            actions=[pop_vlan(),
                                     output(unis[0][0])])
                        #                    ofp.ofp_bucket(actions=[pop_vlan(), output(unis[1][0])])
                    ])))
        stub.UpdateLogicalDeviceFlowTable(
            FlowTableUpdate(id=logical_device_id,
                            flow_mod=mk_simple_flow_mod(
                                priority=1000,
                                match_fields=[
                                    in_port(nni_port_no),
                                    eth_type(0x800),
                                    vlan_vid(4096 + 140),
                                    ipv4_dst(0xe4020202)
                                ],
                                actions=[group(2)])))

        # 3rd with empty bucket
        stub.UpdateLogicalDeviceFlowGroupTable(
            FlowGroupTableUpdate(id=logical_device_id,
                                 group_mod=mk_multicast_group_mod(group_id=3,
                                                                  buckets=[])))
        stub.UpdateLogicalDeviceFlowTable(
            FlowTableUpdate(id=logical_device_id,
                            flow_mod=mk_simple_flow_mod(
                                priority=1000,
                                match_fields=[
                                    in_port(nni_port_no),
                                    eth_type(0x800),
                                    vlan_vid(4096 + 140),
                                    ipv4_dst(0xe4030303)
                                ],
                                actions=[group(3)])))

        self.poutput('success')