Beispiel #1
0
    def _event_switch_enter_handler(self, ev):

        #dpid = datapath.id
        datapath = ev.switch.dp
        dpid = datapath.id

        if dpid in self.LSwitches:

            switch = self.LSwitches[dpid]

            if not switch.get_dp().is_active:
                # switch has restarted
                self.logger.info('%s (%s) has reconnected' %
                                 (dpid_to_empower(dpid), dpid))

                del self.LSwitches[dpid]
                switch = LSwitch(datapath)
                self.LSwitches[dpid] = switch

        else:
            self.logger.info('%s (%s) has connected' %
                             (dpid_to_empower(dpid), dpid))

            switch = LSwitch(datapath)
            switch.remove_ofrule({})
            self.LSwitches[dpid] = switch

        self.agent.send_of_network_item(ev.switch)
Beispiel #2
0
    def _event_switch_enter_handler(self, ev):

        #dpid = datapath.id
        datapath = ev.switch.dp
        dpid = datapath.id

        if dpid in self.LSwitches:

            switch = self.LSwitches[dpid]

            if not switch.get_dp().is_active:
                # switch has restarted
                self.logger.info('%s (%s) has reconnected'
                                 % (dpid_to_empower(dpid), dpid))

                del self.LSwitches[dpid]
                switch = LSwitch(datapath)
                self.LSwitches[dpid] = switch

        else:
            self.logger.info('%s (%s) has connected' %
                             (dpid_to_empower(dpid), dpid))

            switch = LSwitch(datapath)
            switch.remove_ofrule({})
            self.LSwitches[dpid] = switch


        self.agent.send_of_network_item(ev.switch)
Beispiel #3
0
    def _port_status_handler(self, ev):
        msg = ev.msg
        reason = msg.reason
        port_no = msg.desc.port_no

        dpid_str = dpid_to_empower(msg.datapath.id)

        ofproto = msg.datapath.ofproto
        if reason == ofproto.OFPPR_ADD:
            self.logger.info("port added dpid=%s, port=%s", dpid_str, port_no)
        elif reason == ofproto.OFPPR_DELETE:
            self.logger.info("port deleted dpid=%s, port=%s", dpid_str,
                             port_no)
        elif reason == ofproto.OFPPR_MODIFY:
            self.logger.info("port modified dpid=%s, port=%s", dpid_str,
                             port_no)
        else:
            self.logger.info("Illeagal port state dpid=%s, port=%s %s",
                             dpid_str, port_no, reason)
Beispiel #4
0
    def _port_status_handler(self, ev):
        msg = ev.msg
        reason = msg.reason
        port_no = msg.desc.port_no

        dpid_str = dpid_to_empower(msg.datapath.id)

        ofproto = msg.datapath.ofproto
        if reason == ofproto.OFPPR_ADD:
            self.logger.info("port added dpid=%s, port=%s",
                             dpid_str, port_no)
        elif reason == ofproto.OFPPR_DELETE:
            self.logger.info("port deleted dpid=%s, port=%s",
                             dpid_str, port_no)
        elif reason == ofproto.OFPPR_MODIFY:
            self.logger.info("port modified dpid=%s, port=%s",
                             dpid_str, port_no)
        else:
            self.logger.info("Illeagal port state dpid=%s, port=%s %s",
                             dpid_str, port_no, reason)
Beispiel #5
0
    def _packet_in_handler(self, ev):

        msg = ev.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto

        pkt = packet.Packet(msg.data)
        eth = pkt.get_protocol(ethernet.ethernet)
        vlan_pkt = pkt.get_protocol(vlan.vlan)

        if vlan_pkt is not None:
            # vlan-tagged vnf traffic is related to rules
            # and has its own circuits
            return

        if eth.ethertype == ether_types.ETH_TYPE_LLDP:
            # ignore lldp packet
            return

        if eth.ethertype == ether_types.ETH_TYPE_IPV6:
            # ignore IPV6 Packets
            return

        dst = eth.dst.upper()
        src = eth.src.upper()

        if int(dst.split(':')[0], BASE_HEX) & 1 \
                and dst != "FF:FF:FF:FF:FF:FF" \
                and dst != "00:00:00:00:00:00":
            # ignore multicast packets, but allow broadcast packets
            return

        try:

            self.mutex.acquire()

            dpid = datapath.id

            if dpid in self.LSwitches:

                switch = self.LSwitches[dpid]

                if not switch.get_dp().is_active:

                    # switch has restarted
                    self.logger.info('%s (%s) has reconnected' %
                                     (dpid_to_empower(dpid), dpid))

                    del self.LSwitches[dpid]
                    switch = LSwitch(datapath)
                    self.LSwitches[dpid] = switch

            else:
                self.logger.info('%s (%s) has connected' %
                                 (dpid_to_empower(dpid), dpid))

                switch = LSwitch(datapath)
                switch.flowmod(fm_type='DEL', match={})
                self.LSwitches[dpid] = switch

            # for both src and dst check whether these are controlled by Empower
            empower_src_list = [
                endpoint for endpoint in self.endpoints.values()
                if src in endpoint.hwaddr_to_port
            ]
            assert len(empower_src_list) <= 1
            empower_src = None
            if len(empower_src_list) == 1:
                empower_src = empower_src_list[0]

            empower_dst_list = [
                endpoint for endpoint in self.endpoints.values()
                if dst in endpoint.hwaddr_to_port
            ]
            assert len(empower_dst_list) <= 1
            empower_dst = None
            if len(empower_dst_list) == 1:
                empower_dst = empower_dst_list[0]

            # in case both src and dst are unknown to Empower, proceed with
            # regular learning switch
            if empower_src is None and empower_dst is None:

                # learn a mac address to avoid FLOOD next time.
                switch.update_host(src, msg.in_port)

                out_port = switch.get_host_port(dst)

                if out_port is None:
                    switch.packet_out(msg, ofproto.OFPP_FLOOD)
                else:
                    switch.flowmod(src=src,
                                   dst=dst,
                                   in_port=msg.in_port,
                                   out_port=out_port)
                    switch.packet_out(msg, out_port)

            else:

                # either src or dst are Empower controlled,
                target_dpid, target_port = None, None

                if empower_dst is None:
                    target_dpid, target_port = self._find_host_dpid(dst)

                if empower_dst is not None:
                    endpoint_port = empower_dst.hwaddr_to_port[dst]
                    target_dpid = endpoint_port.endpoint.dpid
                    target_port = endpoint_port.port_no

                if target_dpid is None:

                    switch.packet_out(msg, ofproto.OFPP_FLOOD)
                    return

                _, nexthop_port = self._get_nexthop(switch.get_dp_id(),
                                                    target_dpid)

                if nexthop_port is None:
                    nexthop_port = target_port

                switch.flowmod(src=src,
                               dst=dst,
                               in_port=msg.in_port,
                               out_port=nexthop_port,
                               priority=OFP_RULE_PRIORITY)
                switch.packet_out(msg, nexthop_port)

        except Exception:
            traceback.print_exc()
            raise
        finally:
            self.mutex.release()