コード例 #1
0
ファイル: rfproxy.py プロジェクト: Yokoloki/RouteFlow
    def on_packet_in(self, ev):
        msg = ev.msg
        dp = msg.datapath
        dpid = dp.id
        pkt_ethernet = ethernet.parser(msg.data)
        pkt = pkt_ethernet[0]
        
        for f in msg.match.fields:
            if f.header == dp.ofproto.OXM_OF_IN_PORT:
                in_port = f.value

        # If we have a mapping packet, inform RFServer through a Map message
        if pkt.ethertype == RF_ETH_PROTO:
            vm_id, vm_port = struct.unpack("QB", msg.data[14:23])
            log.info("Received mapping packet (vm_id=%s, vm_port=%d, "
                     "vs_id=%s, vs_port=%d)", format_id(vm_id), vm_port,
                     dpid_to_str(dpid), in_port)
            msg = VirtualPlaneMap(vm_id=vm_id, vm_port=vm_port, vs_id=dpid,
                                  vs_port=in_port)
            self.ipc.send(RFSERVER_RFPROXY_CHANNEL, RFSERVER_ID, msg)
            return

        # If the packet came from RFVS, redirect it to the right switch port
        if is_rfvs(dpid):
            dp_port = self.table.vs_port_to_dp_port(dpid, in_port)
            if dp_port is not None:
                dp_id, dp_port = dp_port
                switch = self.switches._get_switch(dp_id)
                if switch is not None:
                    send_pkt_out(switch.dp, dp_port, msg.data)
                    log.debug("forwarding packet from rfvs (vs_id: %s, "
                             "vs_port: %d)", dpid_to_str(dp_id), dp_port)
                else:
                    log.debug("dropped packet from rfvs (vs_id: %s, "
                             "vs_port: %d)", dpid_to_str(dp_id), dp_port)
            else:
                log.debug("Unmapped RFVS port (vs_id=%s, vs_port=%d)",
                         dpid_to_str(dpid), in_port)
        # If the packet came from a switch, redirect it to the right RFVS port
        else:
            vs_port = self.table.dp_port_to_vs_port(dpid, in_port)
            if vs_port is not None:
                vs_id, vs_port = vs_port
                switch = self.switches._get_switch(vs_id)
                if switch is not None:
                    send_pkt_out(switch.dp, vs_port, msg.data)
                    log.debug("forwarding packet to rfvs (dp_id: %s, "
                              "dp_port: %d)", dpid_to_str(vs_id), vs_port)
                else:
                    log.debug("dropped packet to rfvs (dp_id: %s, "
                             "dp_port: %d)", dpid_to_str(dp_id), dp_port)
            else:
                log.debug("Unmapped datapath port (dp_id=%s, dp_port=%d)",
                         dpid_to_str(dpid), in_port)
コード例 #2
0
ファイル: rfproxy.py プロジェクト: vdham/ryu-rfproxy
    def on_packet_in(self, ev):
        msg = ev.msg
        dp = msg.datapath
        dpid = dp.id
        pkt, _ = ethernet.parser(msg.data)

        for f in msg.match.fields:
            if f.header == dp.ofproto.OXM_OF_IN_PORT:
                in_port = f.value

        # If we have a mapping packet, inform RFServer through a Map message
        if pkt.ethertype == RF_ETH_PROTO:
            vm_id, vm_port = struct.unpack("QB", msg.data[14:23])
            log.info("Received mapping packet (vm_id=%s, vm_port=%d, "
                     "vs_id=%s, vs_port=%d)", format_id(vm_id), vm_port,
                     dpid_to_str(dpid), in_port)
            msg = VirtualPlaneMap(vm_id=vm_id, vm_port=vm_port, vs_id=dpid,
                                  vs_port=in_port)
            self.ipc.send(RFSERVER_RFPROXY_CHANNEL, RFSERVER_ID, msg)
            return

        # If the packet came from RFVS, redirect it to the right switch port
        if is_rfvs(dpid):
            dp_port = self.table.vs_port_to_dp_port(dpid, in_port)
            if dp_port is not None:
                dp_id, dp_port = dp_port
                switch = self.switches._get_switch(dp_id)
                if switch is not None:
                    send_pkt_out(switch.dp, dp_port, msg.data)
                    log.debug("forwarding packet from rfvs (dp_id: %s, "
                             "dp_port: %d)", dpid_to_str(dp_id), dp_port)
                else:
                    log.warn("dropped packet from rfvs (dp_id: %s, "
                             "dp_port: %d)", dpid_to_str(dp_id), dp_port)
            else:
                log.info("Unmapped RFVS port (vs_id=%s, vs_port=%d)",
                         dpid_to_str(dpid), in_port)
        # If the packet came from a switch, redirect it to the right RFVS port
        else:
            vs_port = self.table.dp_port_to_vs_port(dpid, in_port)
            if vs_port is not None:
                vs_id, vs_port = vs_port
                switch = self.switches._get_switch(vs_id)
                if switch is not None:
                    send_pkt_out(switch.dp, vs_port, msg.data)
                    log.debug("forwarding packet to rfvs (vs_id: %s, "
                              "vs_port: %d)", dpid_to_str(vs_id), vs_port)
                else:
                    log.warn("dropped packet to rfvs (vs_id: %s, "
                             "vs_port: %d)", dpid_to_str(dp_id), dp_port)
            else:
                log.info("Unmapped datapath port (dp_id=%s, dp_port=%d)",
                         dpid_to_str(dpid), in_port)
コード例 #3
0
ファイル: test_ethernet.py プロジェクト: 09zwcbupt/ryu
 def test_malformed_ethernet(self):
     m_short_buf = self.buf[1:ethernet._MIN_LEN]
     ethernet.parser(m_short_buf)
コード例 #4
0
 def test_malformed_ethernet(self):
     m_short_buf = self.buf[1:ethernet._MIN_LEN]
     ethernet.parser(m_short_buf)