Exemple #1
0
 def flush_address_cache(self):
     links = self.get_all_links()
     peers = {}
     for link in links:
         peers['%d.%d' % (link.src.dpid, link.src.port_no)] = link.dst
     for router_id in self.address_cache:
         ips = {}
         for port_no in self.address_cache[router_id]:
             nw, mask, ip = self.do_set_port_address(
                 self.address_cache[router_id][port_no],
                 router_id,
                 port_no)
             peer_ip = None
             if ENABLE_BFD:
                 try:
                     peer = peers['%d.%d' % (router_id, port_no)]
                     peer_ip = self.address_cache[peer.dpid][peer.port_no]
                     dummy, dummy, peer_ip = nw_addr_aton(peer_ip)
                 except KeyError:
                     pass
             ips[port_no] = [nw, mask, ip, peer_ip]
         self.local_apps[router_id].batch_set_port_address(ips)
         for port_no in ips:
             self.send_event_to_observers(EventAddressAdd(Address(
                 router_id, port_no, ips[port_no][2], ips[port_no][1])))
     self.address_cache = {}
Exemple #2
0
 def flush_address_cache(self):
     links = self.get_all_links()
     peers = {}
     for link in links:
         peers['%d.%d' % (link.src.dpid, link.src.port_no)] = link.dst
     for router_id in self.address_cache:
         ips = {}
         for port_no in self.address_cache[router_id]:
             nw, mask, ip = self.do_set_port_address(
                 self.address_cache[router_id][port_no], router_id, port_no)
             peer_ip = None
             if ENABLE_BFD:
                 try:
                     peer = peers['%d.%d' % (router_id, port_no)]
                     peer_ip = self.address_cache[peer.dpid][peer.port_no]
                     dummy, dummy, peer_ip = nw_addr_aton(peer_ip)
                 except KeyError:
                     pass
             ips[port_no] = [nw, mask, ip, peer_ip]
         self.local_apps[router_id].batch_set_port_address(ips)
         for port_no in ips:
             self.send_event_to_observers(
                 EventAddressAdd(
                     Address(router_id, port_no, ips[port_no][2],
                             ips[port_no][1])))
     self.address_cache = {}
Exemple #3
0
    def do_set_port_address(self, address, router_id, port_no):
        nw, mask, ip = nw_addr_aton(address)
        # Check address overlap
        for port in self.ports[router_id].values():
            if port.ip is None:
                continue
            if (port.nw == ipv4_apply_mask(ip, port.netmask)
                    or nw == ipv4_apply_mask(port.ip, mask)):
                self._logger.error('IP %s overlaps with %s/%d of %d.%d.',
                                   address, port.ip, port.netmask,
                                   port.port.dpid, port.port.port_no)
                return None

        self._logger.info('Setting address of %d.%d', router_id, port_no)
        self.ports[router_id][port_no].set_ip(ip, mask, nw)
        return nw, mask, ip
Exemple #4
0
 def add_entry(self, dst_ip, in_port, out_group):
     dst, netmask, ip_str = nw_addr_aton(dst_ip)
     key = '%d:%s/%d' % (in_port, dst, netmask)
     with self._lock:
         if key in self:
             self._logger.error('Route %s overlapped.', key)
             return
     routing_data = _Route(route_id=self.route_id,
                           dst_ip=dst,
                           netmask=netmask,
                           in_port=in_port,
                           out_group=out_group)
     with self._lock:
         self[key] = routing_data
     self.route_id += 1
     return routing_data
Exemple #5
0
 def add_entry(self, dst_ip, in_port, out_group):
     dst, netmask, ip_str = nw_addr_aton(dst_ip)
     key = '%d:%s/%d' % (in_port, dst, netmask)
     with self._lock:
         if key in self:
             self._logger.error('Route %s overlapped.', key)
             return
     routing_data = _Route(route_id=self.route_id,
                           dst_ip=dst,
                           netmask=netmask,
                           in_port=in_port,
                           out_group=out_group)
     with self._lock:
         self[key] = routing_data
     self.route_id += 1
     return routing_data
Exemple #6
0
    def do_set_port_address(self, address, router_id, port_no):
        nw, mask, ip = nw_addr_aton(address)
        # Check address overlap
        for port in self.ports[router_id].values():
            if port.ip is None:
                continue
            if (port.nw == ipv4_apply_mask(ip, port.netmask)
                or nw == ipv4_apply_mask(port.ip, mask)):
                self._logger.error('IP %s overlaps with %s/%d of %d.%d.',
                                   address,
                                   port.ip,
                                   port.netmask,
                                   port.port.dpid,
                                   port.port.port_no)
                return None

        self._logger.info('Setting address of %d.%d', router_id, port_no)
        self.ports[router_id][port_no].set_ip(ip, mask, nw)
        return nw, mask, ip
Exemple #7
0
    def add(self, router, dst_ip, gateway_ip, src_mac, gateway_mac, out_port,
            in_port=None, out_group=None):
        dst, netmask, dummy = nw_addr_aton(dst_ip)
        gateway_ip = ip_addr_aton(gateway_ip)
        ip_str = ip_addr_ntoa(dst)
        key = '%s/%d' % (ip_str, netmask)
        overlap_route = None
        if key in self:
            overlap_route = self[key].route_id

        if overlap_route is not None:
            self._logger.info('Destination overlaps route id: %d',
                              overlap_route)
            return

        routing_data = BaseRoute(self.route_id, dst, netmask, gateway_ip,
                                 src_mac, gateway_mac, out_port)
        self[key] = routing_data
        self.route_id += 1

        router.install_routing_entry(routing_data)
        return routing_data
Exemple #8
0
    def add(self,
            router,
            dst_ip,
            gateway_ip,
            src_mac,
            gateway_mac,
            out_port,
            in_port=None,
            out_group=None):
        assert in_port is not None
        dst, netmask, dummy = nw_addr_aton(dst_ip)
        if gateway_ip is not None:
            gateway_ip = ip_addr_aton(gateway_ip)
        ip_str = ip_addr_ntoa(dst)
        key = _RoutingTable._get_route_key(ip_str, netmask, in_port)
        overlap_route = None
        if key in self:
            overlap_route = self[key].route_id

        if overlap_route is not None:
            self._logger.info('Destination overlaps route id: %d',
                              overlap_route)
            return

        routing_data = BaseRoute(self.route_id,
                                 dst,
                                 netmask,
                                 gateway_ip,
                                 src_mac,
                                 gateway_mac,
                                 out_port,
                                 in_port=in_port,
                                 out_group=out_group)
        self[key] = routing_data
        self.route_id += 1

        router.install_routing_entry(routing_data)
Exemple #9
0
    def set_port_address(self, ip_str, port_no):
        nw, mask, ip = nw_addr_aton(ip_str)
        # Check overlaps
        mask_b = mask_ntob(mask)
        for port in self.ports.values():
            if port.ip is None:
                continue
            port_mask = mask_ntob(port.netmask)
            if (port.nw == ipv4_apply_mask(ip, port.netmask)
                or nw == ipv4_apply_mask(port.ip, mask)):
                return None
        if port_no not in self.ports.keys():
            return None
        self.ports[port_no].set_ip(nw, mask, ip)
        self._logger.info('Setting IP %s/%d of %s', ip, mask, nw)

        priority, dummy = get_priority(PRIORITY_MAC_LEARNING)
        self.ofctl.set_packet_in_flow(0, priority, eth_type=ether.ETH_TYPE_IP,
                                      dst_ip=nw, dst_mask=mask)
        self._logger.info('Set MAC learning for %s', ip)
        # IP handling
        priority, dummy = get_priority(PRIORITY_IP_HANDLING)
        self.ofctl.set_packet_in_flow(0, priority, eth_type=ether.ETH_TYPE_IP,
                                      dst_ip=ip)
        self._logger.info('Set IP handling for %s', ip)
        # L2 switching
        out_port = self.ofctl.dp.ofproto.OFPP_NORMAL
        priority, dummy = get_priority(PRIORITY_L2_SWITCHING)
        self.ofctl.set_routing_flow(
            0, priority, out_port,
            nw_src=nw, src_mask=mask,
            nw_dst=nw, dst_mask=mask)
        self._logger.info('Set L2 switching (normal) flow [cookie=0x%x]',
                          0)
        # Send GARP
        self.send_arp_request(ip, ip)
        return {'ip': ip, 'mask': mask, 'nw': nw}