def add_flow(self,
                 datapath,
                 priority,
                 match,
                 actions,
                 buffer_id=None,
                 table_id=1,
                 idle_timeout=120,
                 hard_timeout=120):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        inst = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)
        ]
        if buffer_id:
            mod = parser.OFPFlowMod(datapath=datapath,
                                    buffer_id=buffer_id,
                                    idle_timeout=idle_timeout,
                                    hard_timeout=hard_timeout,
                                    priority=priority,
                                    table_id=table_id,
                                    match=match,
                                    instructions=inst)
        else:
            mod = parser.OFPFlowMod(datapath=datapath,
                                    idle_timeout=idle_timeout,
                                    hard_timeout=hard_timeout,
                                    priority=priority,
                                    table_id=table_id,
                                    match=match,
                                    instructions=inst)
        datapath.send_msg(mod)
        self.Flowcounter[datapath.id] += 1
    def switch_features_handler(self, ev):

        msg = ev.msg
        dp = msg.datapath

        # Install default flow rule
        match = parser.OFPMatch()
        action = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER)]
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, action)
        ]

        flowmod = parser.OFPFlowMod(dp,
                                    match=match,
                                    instructions=instruction,
                                    priority=0,
                                    hard_timeout=0,
                                    idle_timeout=0,
                                    cookie=0)

        dp.send_msg(flowmod)

        # Install flow rule 1
        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_dst=('22.0.0.0', '255.0.0.0'))
        action = [parser.OFPActionOutput(2)]
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, action)
        ]

        flowmod = parser.OFPFlowMod(dp,
                                    match=match,
                                    instructions=instruction,
                                    priority=3,
                                    hard_timeout=0,
                                    idle_timeout=0,
                                    cookie=1)

        dp.send_msg(flowmod)

        # Install flow rule 2
        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_dst=('33.0.0.0', '255.0.0.0'))
        action = [parser.OFPActionOutput(3)]
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, action)
        ]

        flowmod = parser.OFPFlowMod(dp,
                                    match=match,
                                    instructions=instruction,
                                    priority=3,
                                    hard_timeout=0,
                                    idle_timeout=0,
                                    cookie=2)

        dp.send_msg(flowmod)
Exemple #3
0
    def install_flows(self, datapath, has_group, stateful):
        print("Configuring flow table for switch %d" % datapath.id)
        if stateful:
            self.send_table_mod(datapath)
            self.send_key_lookup(datapath)
            self.send_key_update(datapath)

        # group entries installation
        if has_group:
            self.install_group_entries(datapath)

        # flow entries installation
        if datapath.id in f_t_parser.flow_entries_dict.keys():
            for flow_entry in f_t_parser.flow_entries_dict[datapath.id]:
                mod = ofparser.OFPFlowMod(datapath=datapath,
                                          cookie=0,
                                          cookie_mask=0,
                                          table_id=flow_entry['table_id'],
                                          command=ofproto.OFPFC_ADD,
                                          idle_timeout=0,
                                          hard_timeout=0,
                                          priority=32768,
                                          buffer_id=ofproto.OFP_NO_BUFFER,
                                          out_port=ofproto.OFPP_ANY,
                                          out_group=ofproto.OFPG_ANY,
                                          flags=0,
                                          match=flow_entry['match'],
                                          instructions=flow_entry['inst'])
                datapath.send_msg(mod)

        for primary_entry_key in f_t_parser.redirect_primary_dict.keys():
            if primary_entry_key[0] == datapath.id:
                for flow_entry in f_t_parser.redirect_primary_dict[
                        primary_entry_key]:
                    mod = ofparser.OFPFlowMod(datapath=datapath,
                                              cookie=0,
                                              cookie_mask=0,
                                              table_id=flow_entry['table_id'],
                                              command=ofproto.OFPFC_ADD,
                                              idle_timeout=0,
                                              hard_timeout=0,
                                              priority=32768,
                                              buffer_id=ofproto.OFP_NO_BUFFER,
                                              out_port=ofproto.OFPP_ANY,
                                              out_group=ofproto.OFPG_ANY,
                                              flags=0,
                                              match=flow_entry['match'],
                                              instructions=flow_entry['inst'])
                    datapath.send_msg(mod)

        self.switch_count += 1
        if self.switch_count == f_t_parser.G.number_of_nodes():
            self.monitor_thread = hub.spawn(self._monitor, datapath)
Exemple #4
0
    def send_flow(self, path, prio, mtch, acts, buid=None):
        cmd = [parser.OFPInstructionActions(proto.OFPIT_APPLY_ACTIONS, acts)]

        if buid:
            mod = parser.OFPFlowMod(datapath=path,
                                    priority=prio,
                                    match=mtch,
                                    instructions=cmd,
                                    buffer_id=buid)
        else:
            mod = parser.OFPFlowMod(datapath=path,
                                    priority=prio,
                                    match=mtch,
                                    instructions=cmd)
        path.send_msg(mod)
Exemple #5
0
    def add_routes(self, datapath, local_port, mac):
        """ Add the routes to all switches when a new mac is learned """
        # Add the route to the switch the device is connected to
        local_route = parser.OFPFlowMod(
            datapath=datapath,
            table_id=0,
            priority=20,
            cookie=3,
            command=ofproto.OFPFC_ADD,
            match=parser.OFPMatch(eth_dst=mac),
            instructions=[
                parser.OFPInstructionGotoTable(1),
                parser.OFPInstructionActions(
                    type_=ofproto.OFPIT_WRITE_ACTIONS,
                    actions=[parser.OFPActionOutput(local_port)])
            ])
        datapath.send_msg(local_route)

        # Now add routes to all other switches that can get there
        bfs = self.breadth_first_search(datapath.id)
        for dpid, port in bfs.iteritems():
            dp = self.switches[dpid]
            foreign_route = parser.OFPFlowMod(
                datapath=dp,
                table_id=0,
                priority=10,
                cookie=3,
                command=ofproto.OFPFC_ADD,
                match=parser.OFPMatch(eth_dst=mac),
                instructions=[
                    parser.OFPInstructionGotoTable(1),
                    parser.OFPInstructionActions(
                        type_=ofproto.OFPIT_WRITE_ACTIONS,
                        actions=[parser.OFPActionOutput(port)])
                ])
            dp.send_msg(foreign_route)

        # Add the route to table 1 so we don't get messages about
        # this mac address anymore
        for dp in self.switches.values():
            block_route = parser.OFPFlowMod(datapath=dp,
                                            table_id=1,
                                            priority=20,
                                            cookie=3,
                                            command=ofproto.OFPFC_ADD,
                                            match=parser.OFPMatch(eth_src=mac),
                                            instructions=[])
            dp.send_msg(block_route)
Exemple #6
0
    def installReturnNoTagFlowEntry(self, datapath):
        '''
        Install the return no tag flow entry - relevant for the case of 4 flow entries only.
        :param datapath: datapath which represent the switch to install the flow entries on.
        '''

        #If we are working with 3 flow entries only, return because need to install nothing.
        if (3 == self.numberOfFlowEntries):
            return

        # Get the switch ID
        switchID = datapath.id

        # Match if the packet has return no tag Ethertype. Equivalent to return with setIDFlag TRUE.
        returnNoTagMatch = ofproto_v1_3_parser.OFPMatch(
            eth_type=ExtraLayers.dirReturnNoTag)

        # Get actions.
        returnNoTagActions = self.actionsGenerator.getReturnNoTagActions(
            switchID)

        # The instructions are apply actions with the return no tag Actions - apply actions by order.
        SecondReturnInst = [
            ofproto_v1_3_parser.OFPInstructionActions(
                datapath.ofproto.OFPIT_APPLY_ACTIONS, returnNoTagActions)
        ]

        # Prepare the flow entry.
        mod = ofproto_v1_3_parser.OFPFlowMod(datapath=datapath,
                                             priority=NORMAL_PRIO,
                                             match=returnNoTagMatch,
                                             instructions=SecondReturnInst)
        datapath.send_msg(mod)
Exemple #7
0
    def installReturnAndTagFlowEntry(self, datapath):
        '''
        Install return and tag flow entry. This flow entry is different for the 3 or 4 flow entries case, and the matching is different
        :param datapath: datapath which represent the switch to install the flow entries on.
        '''

        # Get the ethertype to match on for the case of 3 flow entries or 4 flow entries
        if (3 == self.numberOfFlowEntries):
            ethTypeMatch = ExtraLayers.dirBackwardsThreeFlowEntries
        else:
            # Equivalent to return with setIDFlag TRUE.
            ethTypeMatch = ExtraLayers.dirReturnAndTag

        # Get the switch ID.
        switchID = datapath.id

        # Match if this is a return and tag probe pacekt (4 flow entries case) or dir backwards if 3 flow entries.
        FirstReturnMatch = ofproto_v1_3_parser.OFPMatch(eth_type=ethTypeMatch)

        # Get actions.
        returnAndTagActions = self.actionsGenerator.getReturnAndTagActions(
            switchID, self.numberOfFlowEntries)

        # The instructions are apply actions with the return and tag Actions - apply actions by order.
        returnAndTagActions = [
            ofproto_v1_3_parser.OFPInstructionActions(
                datapath.ofproto.OFPIT_APPLY_ACTIONS, returnAndTagActions)
        ]

        # Prepare the flow entry.#prepare the message for flow installing on given switch, priority, match and instructions
        mod = ofproto_v1_3_parser.OFPFlowMod(datapath=datapath,
                                             priority=NORMAL_PRIO,
                                             match=FirstReturnMatch,
                                             instructions=returnAndTagActions)
        datapath.send_msg(mod)
Exemple #8
0
    def installDoNotDistributeFlowEntry(self, datapath):
        '''
        Install the do not distribute flow entry. for matching the flow entries are the same for the case of 3 or 4 flow entries.
        :param datapath: datapath which represent the switch to install the flow entries on.
        '''

        #Get the switch ID
        switchID = datapath.id

        # Match if the probe packet is directed forward (equivalent to forward and setIDFlag TRUE).
        doNotDistributeMatch = ofproto_v1_3_parser.OFPMatch(
            eth_type=ExtraLayers.dirForward)

        # Get the do not distribute actions.
        doNotDistributeActions = self.actionsGenerator.getDoNotDistributeActions(
            switchID, self.numberOfFlowEntries)

        # The instructions are apply actions with the return and tag Actions - apply actions by order.
        doNotDistributeInst = [
            ofproto_v1_3_parser.OFPInstructionActions(
                datapath.ofproto.OFPIT_APPLY_ACTIONS, doNotDistributeActions)
        ]

        # Prepare the flow entry.
        mod = ofproto_v1_3_parser.OFPFlowMod(datapath=datapath,
                                             priority=NORMAL_PRIO,
                                             match=doNotDistributeMatch,
                                             instructions=doNotDistributeInst)
        datapath.send_msg(mod)
Exemple #9
0
    def installDistributeFlowEntry(self, datapath):
        '''
        Install the distribution flow entry, Same fore the ccase of 3 or 4 flow entries.
        :param datapath: datapath which represent the switch to install the flow entries on.
        '''

        # Get the switch ID.
        switchID = datapath.id

        # Get the parent port for the match.
        parentPort = (self.actionsGenerator.switch_to_parent_port[switchID])

        # Match if the probe packet is directed forward (equivalent to forward and setIDFlag TRUE) and the ingress port is
        # the parent port. For safety , added also NULL ID in vlan.
        ForwardingMatch = ofproto_v1_3_parser.OFPMatch(
            in_port=parentPort,
            eth_type=ExtraLayers.dirForward,
            vlan_vid=ExtraLayers.NULL_ID)

        # Get the distribution actions.
        distributionActions = self.actionsGenerator.getDistributionActions(
            switchID, self.numberOfFlowEntries)

        # The instructions are apply actions with the distribution Actions - apply actions by order.
        forwardingInst = [
            ofproto_v1_3_parser.OFPInstructionActions(
                datapath.ofproto.OFPIT_APPLY_ACTIONS, distributionActions)
        ]

        # Prepare the flow entry (NOTE: higher priority).
        mod = ofproto_v1_3_parser.OFPFlowMod(datapath=datapath,
                                             priority=DISTRIBUTE_PRIO,
                                             match=ForwardingMatch,
                                             instructions=forwardingInst)
        datapath.send_msg(mod)
Exemple #10
0
    def installTestStarFlowEntries(self):
        """
        Code written for specific test on start topology. (Measure duplication and tagging time).
        :return:
        """

        datapath1 = self.id_to_datapath[1]
        datapath2 = self.id_to_datapath[2]

        # Install the flow entries on the MP.
        Match = ofproto_v1_3_parser.OFPMatch(
            in_port=1,
            eth_type=ExtraLayers.typeForTestingTaggingAndDuplicationTime)
        Actions = [
            ofproto_v1_3_parser.OFPActionOutput(0xfffffffd),
            ofproto_v1_3_parser.OFPActionOutput(0xfffffffd),
            ofproto_v1_3_parser.OFPActionPopVlan(),
            ofproto_v1_3_parser.OFPActionSetField(
                eth_type=ExtraLayers.dirBackwardsThreeFlowEntries),
            ofproto_v1_3_parser.OFPActionPushVlan(
                ethertype=ExtraLayers.VLAN_ID_ETHERTYPE_QINQ),
            ofproto_v1_3_parser.OFPActionSetField(vlan_vid=1),
            ofproto_v1_3_parser.OFPActionOutput(0xfffffffd)
        ]
        Inst = [
            ofproto_v1_3_parser.OFPInstructionActions(
                datapath1.ofproto.OFPIT_APPLY_ACTIONS, Actions)
        ]
        mod = ofproto_v1_3_parser.OFPFlowMod(
            datapath=datapath1,
            priority=NORMAL_SWITCH_FORWARDING_PRIO,
            match=Match,
            instructions=Inst)
        datapath1.send_msg(mod)
Exemple #11
0
    def _packet_in_handler(self, ev):
        """
        Handler for messages which are send from the controller (table2).
        This handler creates a rule in the flow table (table 2).

        Parameters:
            - ev    = mesage from the controller
        """
        # Parse data from message
        msg = ev.msg
        datapath = msg.datapath
        orig_match = msg.match

        if not ("ipv4_dst" in orig_match):
            LOG.info("No IPv4 destination IP has been detected.")

        dst_ipv4 = orig_match["ipv4_dst"]

        # So far so good, create a new record in the flow table
        # TOOO: TIMEOUTS
        match = ofparser.OFPMatch(eth_type=0x0800,
                                  ipv4_dst=dst_ipv4,
                                  ip_proto=6)
        mod = ofparser.OFPFlowMod(datapath=datapath,
                                  table_id=2,
                                  priority=1,
                                  match=match)
        datapath.send_msg(mod)

        debug_str = "Counting rule for the flow (dst_ip=%s) has been created" % (
            dst_ipv4)
        LOG.info(debug_str)
Exemple #12
0
    def remove_link(self, ev):
        if ev.link.src.dpid in self.switch_graph:
            tmp = ev.link.src.port_no, ev.link.dst.dpid, ev.link.dst.port_no
            self.switch_graph[ev.link.src.dpid] = filter(
                lambda x: x != tmp, self.switch_graph[ev.link.src.dpid])

            if ev.link.src.dpid in self.switch_ports and ev.link.src.port_no not in self.switch_ports[
                    ev.link.src.dpid]:
                self.switch_ports[ev.link.src.dpid].append(ev.link.src.port_no)
            if ev.link.dst.dpid in self.switch_ports and ev.link.dst.port_no not in self.switch_ports[
                    ev.link.dst.dpid]:
                self.switch_ports[ev.link.dst.dpid].append(ev.link.dst.port_no)

            self.set_broadcast_tree()

        # Remove the broadcast rule
        if ev.link.src.dpid in self.switches:
            broadcast_rule = parser.OFPFlowMod(
                datapath=self.switches[ev.link.src.dpid],
                table_id=1,
                priority=10,
                command=ofproto.OFPFC_DELETE,
                match=parser.OFPMatch(in_port=ev.link.src.port_no),
                instructions=[])
            self.switches[ev.link.src.dpid].send_msg(broadcast_rule)
    def install_flow(self,
                     dp,
                     ip_dst,
                     out_port,
                     cookie,
                     priority=0,
                     hard_timeout=0,
                     idle_timeout=0):

        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_dst=(ip_dst, '255.0.0.0'))
        action = [parser.OFPActionOutput(out_port)]
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, action)
        ]

        flowmod = parser.OFPFlowMod(dp,
                                    match=match,
                                    instructions=instruction,
                                    priority=priority,
                                    hard_timeout=hard_timeout,
                                    idle_timeout=idle_timeout,
                                    cookie=cookie,
                                    flags=dp.ofproto.OFPFF_SEND_FLOW_REM)

        dp.send_msg(flowmod)
Exemple #14
0
    def install_flows(self, datapath, stateful, has_group):
        print("Configuring flow table for switch %d" % datapath.id)

        # group entries installation
        if has_group:
            self.install_group_entries(datapath)

        if stateful:
            self.send_table_mod(datapath)
            self.send_key_lookup(datapath)
            self.send_key_update(datapath)

        # flow entries installation
        if datapath.id in f_t_parser.flow_entries_dict.keys():
            for flow_entry in f_t_parser.flow_entries_dict[datapath.id]:
                mod = ofparser.OFPFlowMod(datapath=datapath,
                                          cookie=0,
                                          cookie_mask=0,
                                          table_id=flow_entry['table_id'],
                                          command=ofproto.OFPFC_ADD,
                                          idle_timeout=0,
                                          hard_timeout=0,
                                          priority=10,
                                          buffer_id=ofproto.OFP_NO_BUFFER,
                                          out_port=ofproto.OFPP_ANY,
                                          out_group=ofproto.OFPG_ANY,
                                          flags=0,
                                          match=flow_entry['match'],
                                          instructions=flow_entry['inst'])
                datapath.send_msg(mod)
Exemple #15
0
    def add_lb_flow(self, datapath, mac):
        global inc

        match = datapath.ofproto_parser.OFPMatch(in_port=4,
                                                 eth_type=0x800,
                                                 ip_proto=6,
                                                 ipv4_dst='10.0.0.1',
                                                 eth_dst='00:00:00:00:00:01')
        ip = "10.0.0." + str(self.mac_port[mac])
        eth = "00:00:00:00:00:0" + str(self.mac_port[mac])
        actions = [
            ofparser.OFPActionSetField(ipv4_dst=ip),
            ofparser.OFPActionSetField(eth_dst=eth),
            ofparser.OFPActionSetField(tcp_dst=80),
            ofparser.OFPActionOutput(port=self.mac_port[mac])
        ]
        print "redirected to port ", self.mac_port[mac]

        inst = [
            ofparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                           actions)
        ]
        mod = ofparser.OFPFlowMod(datapath=datapath,
                                  table_id=0,
                                  priority=100,
                                  match=match,
                                  instructions=inst,
                                  hard_timeout=2)
        datapath.send_msg(mod)
Exemple #16
0
    def flow_example_groups(self, dp):
        # a flow to correctly forward all traffic to m1, but implemented using
        # group tables

        # you can specify multiple buckets, and each bucket can perform multple
        # actions
        buckets = [
            parser.OFPBucket(actions=[parser.OFPActionOutput(4)]),
        ]
        # create the group
        # docs: https://ryu.readthedocs.io/en/latest/ofproto_v1_3_ref.html#ryu.ofproto.ofproto_v1_3_parser.OFPGroupMod
        dp.send_msg(
            parser.OFPGroupMod(dp,
                               command=ofproto.OFPGC_ADD,
                               type_=ofproto.OFPGT_SELECT,
                               group_id=1,
                               buckets=buckets))

        # create a match to send packets to the new group
        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_dst='44.0.0.0/8')
        # you've been using this all along, see: self.program_flow in cockpit.py
        instructions = [
            parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                         [parser.OFPActionGroup(group_id=1)])
        ]
        dp.send_msg(
            parser.OFPFlowMod(dp,
                              match=match,
                              instructions=instructions,
                              priority=1))
Exemple #17
0
    def timeout_burst(self, burst):
        f_t_parser.selected_burst = burst

        for datapath_id in self.flow_entries_with_burst_dict[burst]:
            for table_id in self.flow_entries_with_burst_dict[burst][
                    datapath_id]:
                for match in self.flow_entries_with_burst_dict[burst][
                        datapath_id][table_id]:
                    mod = ofparser.OFPFlowMod(
                        datapath=self.dp_dictionary[datapath_id],
                        cookie=0,
                        cookie_mask=0,
                        table_id=table_id,
                        command=ofproto.OFPFC_MODIFY,
                        idle_timeout=0,
                        hard_timeout=0,
                        priority=self.flow_entries_with_burst_dict[burst]
                        [datapath_id][table_id][match]['priority'],
                        buffer_id=ofproto.OFP_NO_BUFFER,
                        out_port=ofproto.OFPP_ANY,
                        out_group=ofproto.OFPG_ANY,
                        flags=0,
                        match=match,
                        instructions=self.flow_entries_with_burst_dict[burst]
                        [datapath_id][table_id][match]['inst'])
                    self.dp_dictionary[datapath_id].send_msg(mod)
Exemple #18
0
    def install_flows(self, datapath):
        print("Configuring flow table for switch %d" % datapath.id)

        if datapath.id in self.flow_entries_dict.keys():
            for table_id in self.flow_entries_dict[datapath.id]:
                for match in self.flow_entries_dict[datapath.id][table_id]:
                    mod = ofparser.OFPFlowMod(
                        datapath=datapath,
                        cookie=0,
                        cookie_mask=0,
                        table_id=table_id,
                        command=ofproto.OFPFC_ADD,
                        idle_timeout=0,
                        hard_timeout=0,
                        priority=self.flow_entries_dict[
                            datapath.id][table_id][match]['priority'],
                        buffer_id=ofproto.OFP_NO_BUFFER,
                        out_port=ofproto.OFPP_ANY,
                        out_group=ofproto.OFPG_ANY,
                        flags=0,
                        match=match,
                        instructions=self.flow_entries_dict[
                            datapath.id][table_id][match]['inst'])
                    datapath.send_msg(mod)

        self.switch_count += 1
        if self.switch_count == self.G.number_of_nodes():
            self.monitor_thread = hub.spawn(self._monitor, datapath)
Exemple #19
0
 def add_flow(self, datapath):
     inst = self.create_actions()
     match_list = self.create_match()
     for match in match_list:
         mod = ofp.OFPFlowMod(datapath=datapath, instructions=inst)
         mod.match = match
         print(mod)
         datapath.send_msg(mod)
Exemple #20
0
    def load_fsm(self, datapath):
        LOG.info("Loading Table 1 (SYN counter) ...")
        ##=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
        """
        Create two records for implementation of SYN counter.  The first one 
        is used for counting of unkwnotn packets with SYN flag. 
        After that, we use the second  record for counting of already known SYN
        flows.
        """
        # Setup the record for matching of unknown SYN
        actions = [
            osparser.OFPExpActionSetState(
                state=self.KNOWN_SYN,
                table_id=1,
                # TODO - TIMEOUTS
                idle_timeout=1)
        ]
        inst = [
            ofparser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)
        ]
        match = ofparser.OFPMatch(eth_type=0x0800,
                                  ip_proto=6,
                                  state=self.UNKNOWN_SYN,
                                  tcp_flags=F_SYN)
        mod = ofparser.OFPFlowMod(datapath=datapath,
                                  table_id=1,
                                  priority=1,
                                  match=match,
                                  instructions=inst)
        datapath.send_msg(mod)

        actions = []
        inst = [
            ofparser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)
        ]
        match = ofparser.OFPMatch(eth_type=0x0800,
                                  ip_proto=6,
                                  state=self.KNOWN_SYN,
                                  tcp_flags=F_SYN)
        mod = ofparser.OFPFlowMod(datapath=datapath,
                                  table_id=1,
                                  priority=1,
                                  match=match,
                                  instructions=inst)
        datapath.send_msg(mod)
 def set_flow(self, datapath, match, actions, priority=0, hard_timeout=600, idle_timeout=60):
     inst    = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
     flowmod = parser.OFPFlowMod(datapath, 
         match=match,
         instructions=inst,
         priority=priority,
         hard_timeout=hard_timeout,
         idle_timeout=idle_timeout)
     datapath.send_msg(flowmod)
	def add_flow(self, datapath, table_id, priority, match, actions):
		if len(actions) > 0:
			inst = [ofparser.OFPInstructionActions(
					ofproto.OFPIT_APPLY_ACTIONS, actions)]
		else:
			inst = []
		mod = ofparser.OFPFlowMod(datapath=datapath, table_id=table_id,
								priority=priority, match=match, instructions=inst)
		datapath.send_msg(mod)
Exemple #23
0
    def add_flow(self, datapath, priority, match, actions):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # construct flow_mod message and send it.
        inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                             actions)]
        mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
                                match=match, instructions=inst)
        datapath.send_msg(mod)
Exemple #24
0
 def add_flow1(self, datapath, table_id, priority, match, actions):
     inst = [
         ofparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                        actions)
     ]
     mod = ofparser.OFPFlowMod(datapath=datapath,
                               table_id=table_id,
                               priority=priority,
                               match=match,
                               instructions=inst)
     datapath.send_msg(mod)
     print "normal flow added"
Exemple #25
0
    def dp_connect(self, ryu_event):
        logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
        datapath = ryu_event.dp
        for of_port in datapath.ports.values():
            self.report_port(of_port)
        mods = []
        # Drop all flows.
        mods.append(
            parser.OFPFlowMod(
                datapath=datapath,
                command=ofp.OFPFC_DELETE,
                out_port=ofp.OFPP_ANY,
                out_group=ofp.OFPG_ANY,
            ))
        # Default deny all tables
        for table_id in (self.INTF_TABLE, self.FROM_COPRO_TABLE,
                         self.TO_COPRO_TABLE):
            mods.append(
                parser.OFPFlowMod(datapath=datapath,
                                  command=ofp.OFPFC_ADD,
                                  table_id=table_id,
                                  priority=0,
                                  instructions=[]))

        for nfvlan, nfvip in zip(VLANS, NFVIPS):
            vlan_id = (nfvlan | ofp.OFPVID_PRESENT)
            if nfvip.version == 6:
                flows = self.ipv6_flows
            else:
                flows = self.ipv4_flows
            for table_id, match, instructions in flows(vlan_id, nfvip):
                mods.append(
                    parser.OFPFlowMod(datapath=datapath,
                                      command=ofp.OFPFC_ADD,
                                      table_id=table_id,
                                      priority=1,
                                      match=match,
                                      instructions=instructions))
        self.send_mods(datapath, mods)
Exemple #26
0
def flowmod(cookie, command, table_id, priority, out_port, out_group,
            match_fields, inst, hard_timeout, idle_timeout):
    return parser.OFPFlowMod(datapath=None,
                             cookie=cookie,
                             command=command,
                             table_id=table_id,
                             priority=priority,
                             out_port=out_port,
                             out_group=out_group,
                             match=match_fields,
                             instructions=inst,
                             hard_timeout=hard_timeout,
                             idle_timeout=idle_timeout)
 def add_tcp_table(self, datapath):
     ofproto = datapath.ofproto
     parser = datapath.ofproto_parser
     inst = [parser.OFPInstructionGotoTable(1)]
     match = parser.OFPMatch()
     mod = parser.OFPFlowMod(datapath=datapath,
                             table_id=0,
                             priority=0,
                             match=match,
                             idle_timeout=0,
                             hard_timeout=0,
                             instructions=inst)
     datapath.send_msg(mod)
     self.Flowcounter[datapath.id] += 1
Exemple #28
0
 def add_pktgen_flow(self, datapath, table_id, priority, match, pkttmp_id,
                     actions):
     if len(actions) > 0:
         inst = [
             bebaparser.OFPInstructionInSwitchPktGen(pkttmp_id, actions)
         ]
     else:
         inst = []
     mod = ofparser.OFPFlowMod(datapath=datapath,
                               table_id=table_id,
                               priority=priority,
                               match=match,
                               instructions=inst)
     datapath.send_msg(mod)
Exemple #29
0
    def install_forward(self, datapath):

        match = ofparser.OFPMatch()
        actions = [ofparser.OFPActionOutput(ofproto.OFPP_FLOOD)]
        inst = [
            ofparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                           actions)
        ]
        mod = ofparser.OFPFlowMod(datapath=datapath,
                                  table_id=0,
                                  priority=10,
                                  match=match,
                                  instructions=inst)
        datapath.send_msg(mod)
Exemple #30
0
 def add_flow(self, datapath, table_id, priority, match, actions):
     global inc
     inst = [
         ofparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                        actions)
     ]
     mod = ofparser.OFPFlowMod(datapath=datapath,
                               table_id=table_id,
                               priority=priority,
                               match=match,
                               instructions=inst,
                               idle_timeout=self.interval)
     datapath.send_msg(mod)
     print "load balancer flow added"