Esempio n. 1
0
    def _add_resolved_route(self, vlan, ip_gw, ip_dst, eth_dst, is_updated=None):
        ofmsgs = []
        if is_updated is not None:
            in_match = self.valve_in_match(
                self.fib_table, vlan=vlan,
                eth_type=self._eth_type(), nw_dst=ip_dst)
            prefixlen = ipaddr.IPNetwork(ip_dst).prefixlen
            priority = self.route_priority + prefixlen
            if is_updated:
                self.logger.info(
                    'Updating next hop for route %s via %s (%s)',
                    ip_dst, ip_gw, eth_dst)
                ofmsgs.extend(self.valve_flowdel(
                    self.fib_table,
                    in_match,
                    priority=priority))
            else:
                self.logger.info(
                    'Adding new route %s via %s (%s)',
                    ip_dst, ip_gw, eth_dst)

            ofmsgs.append(self.valve_flowmod(
                self.fib_table,
                in_match,
                priority=priority,
                inst=[valve_of.apply_actions(
                    [valve_of.set_eth_src(self.faucet_mac),
                     valve_of.set_eth_dst(eth_dst),
                     valve_of.dec_ip_ttl()])] +
                [valve_of.goto_table(self.eth_dst_table)]))
        now = time.time()
        link_neighbor = LinkNeighbor(eth_dst, now)
        neighbor_cache = self._vlan_neighbor_cache(vlan)
        neighbor_cache[ip_gw] = link_neighbor
        return ofmsgs
Esempio n. 2
0
    def _add_resolved_route(self, vlan, ip_gw, ip_dst, eth_dst, is_updated=None):
        ofmsgs = []
        if is_updated is not None:
            in_match = self.valve_in_match(
                self.fib_table, vlan=vlan,
                eth_type=self._eth_type(), nw_dst=ip_dst)
            prefixlen = ipaddr.IPNetwork(ip_dst).prefixlen
            priority = self.route_priority + prefixlen
            if is_updated:
                self.logger.info(
                    'Updating next hop for route %s via %s (%s)',
                    ip_dst, ip_gw, eth_dst)
                ofmsgs.extend(self.valve_flowdel(
                    self.fib_table,
                    in_match,
                    priority=priority))
            else:
                self.logger.info(
                    'Adding new route %s via %s (%s)',
                    ip_dst, ip_gw, eth_dst)

            ofmsgs.append(self.valve_flowmod(
                self.fib_table,
                in_match,
                priority=priority,
                inst=[valve_of.apply_actions(
                    [valve_of.set_eth_src(self.faucet_mac),
                     valve_of.set_eth_dst(eth_dst),
                     valve_of.dec_ip_ttl()])] +
                [valve_of.goto_table(self.eth_dst_table)]))
        now = time.time()
        link_neighbor = LinkNeighbor(eth_dst, now)
        neighbor_cache = self._vlan_neighbor_cache(vlan)
        neighbor_cache[ip_gw] = link_neighbor
        return ofmsgs
Esempio n. 3
0
 def _add_resolved_route(self, vlan, ip_gw, ip_dst, eth_dst, is_updated=None):
     ofmsgs = []
     if is_updated is not None:
         in_match = self.valve_in_match(
             self.fib_table, vlan=vlan,
             eth_type=self._eth_type(), nw_dst=ip_dst)
         prefixlen = ipaddr.IPNetwork(ip_dst).prefixlen
         priority = self.route_priority + prefixlen
         if is_updated:
             self.logger.info(
                 'Updating next hop for route %s via %s (%s)',
                 ip_dst, ip_gw, eth_dst)
             ofmsgs.extend(self.valve_flowdel(
                 self.fib_table,
                 in_match,
                 priority=priority))
         else:
             self.logger.info(
                 'Adding new route %s via %s (%s)',
                 ip_dst, ip_gw, eth_dst)
         if self.use_group_table:
             inst = [valve_of.apply_actions([valve_of.group_act(
                 group_id=self.ip_gw_to_group_id[ip_gw])])]
         else:
             inst = [valve_of.apply_actions([
                 valve_of.set_eth_src(self.faucet_mac),
                 valve_of.set_eth_dst(eth_dst),
                 valve_of.dec_ip_ttl()]),
                     valve_of.goto_table(self.eth_dst_table)]
         ofmsgs.append(self.valve_flowmod(
             self.fib_table,
             in_match,
             priority=priority,
             inst=inst))
     return ofmsgs
Esempio n. 4
0
 def _nexthop_actions(self, eth_dst, vlan):
     ofmsgs = []
     if self.routers:
         ofmsgs.append(valve_of.set_vlan_vid(vlan.vid))
     ofmsgs.extend([
         valve_of.set_eth_src(self.faucet_mac),
         valve_of.set_eth_dst(eth_dst),
         valve_of.dec_ip_ttl()])
     return ofmsgs
Esempio n. 5
0
    def _update_nexthop(self, vlan, in_port, eth_src, resolved_ip_gw):
        ofmsgs = []
        is_updated = None
        routes = self._vlan_routes(vlan)
        group_mod_method = None
        group_id = None

        nexthop_cache_entry = self._vlan_nexthop_cache_entry(
            vlan, resolved_ip_gw)
        if (nexthop_cache_entry is not None and
                nexthop_cache_entry.eth_src is not None):
            cached_eth_dst = nexthop_cache_entry.eth_src
            if cached_eth_dst != eth_src:
                is_updated = True
                if self.use_group_table:
                    group_mod_method = valve_of.groupmod
                    group_id = self.ip_gw_to_group_id[resolved_ip_gw]
        else:
            is_updated = False
            if self.use_group_table:
                group_mod_method = valve_of.groupadd
                group_id = self._group_id_from_ip_gw(resolved_ip_gw)
                self.ip_gw_to_group_id[resolved_ip_gw] = group_id

        if is_updated is not None:
            if self.use_group_table:
                actions = []
                actions.extend([
                    valve_of.set_eth_src(self.faucet_mac),
                    valve_of.set_eth_dst(eth_src),
                    valve_of.dec_ip_ttl()])
                if not vlan.port_is_tagged(in_port):
                    actions.append(valve_of.pop_vlan())
                actions.append(valve_of.output_port(in_port))
                ofmsgs.append(group_mod_method(
                    group_id=group_id,
                    buckets=[valve_of.bucket(actions=actions)]))

            for ip_dst, ip_gw in routes.iteritems():
                if ip_gw == resolved_ip_gw:
                    ofmsgs.extend(self._add_resolved_route(
                        vlan, ip_gw, ip_dst, eth_src, is_updated))

        self._update_nexthop_cache(vlan, eth_src, resolved_ip_gw)
        return ofmsgs
Esempio n. 6
0
 def _nexthop_actions(self, eth_dst):
     return [
         valve_of.set_eth_src(self.faucet_mac),
         valve_of.set_eth_dst(eth_dst),
         valve_of.dec_ip_ttl()
     ]
Esempio n. 7
0
 def _nexthop_actions(self, eth_dst):
     return [
         valve_of.set_eth_src(self.faucet_mac),
         valve_of.set_eth_dst(eth_dst),
         valve_of.dec_ip_ttl()]