summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorahdj007 <dong.juan1@zte.com.cn>2018-03-08 10:02:17 +0800
committerDamjan Marion <dmarion.lists@gmail.com>2018-03-09 13:05:27 +0000
commit5e85c54d229e443d30dabe9bca39625587add8a5 (patch)
tree61393541c8304bf1fcb7e6a316e0c9248e03fa00 /src/plugins
parent31ed74407643595fdce206e9d7487108fb8b33ab (diff)
when exceed max reass,
frag packet can't get reass. adding bihash,it can rewrite new hash value. so need to delete hash after compare hash value. Change-Id: I83b5c47890110e9a598b78cfbe8fcd27bbe291bb Signed-off-by: ahdj007 <dong.juan1@zte.com.cn>
Diffstat (limited to 'src/plugins')
-rwxr-xr-xsrc/plugins/nat/nat_reass.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/plugins/nat/nat_reass.c b/src/plugins/nat/nat_reass.c
index 50bfced2b45..eb1b4925521 100755
--- a/src/plugins/nat/nat_reass.c
+++ b/src/plugins/nat/nat_reass.c
@@ -228,7 +228,7 @@ nat_ip4_reass_find_or_create (ip4_address_t src, ip4_address_t dst,
dlist_elt_t *oldest_elt, *elt;
dlist_elt_t *per_reass_list_head_elt;
u32 oldest_index, elt_index;
- clib_bihash_kv_16_8_t kv;
+ clib_bihash_kv_16_8_t kv, value;
k.src.as_u32 = src.as_u32;
k.dst.as_u32 = dst.as_u32;
@@ -273,12 +273,18 @@ nat_ip4_reass_find_or_create (ip4_address_t src, ip4_address_t dst,
clib_dlist_addtail (srm->ip4_reass_lru_list_pool,
srm->ip4_reass_head_index, oldest_index);
- kv.key[0] = k.as_u64[0];
- kv.key[1] = k.as_u64[1];
- if (clib_bihash_add_del_16_8 (&srm->ip4_reass_hash, &kv, 0))
+ kv.key[0] = reass->key.as_u64[0];
+ kv.key[1] = reass->key.as_u64[1];
+ if (!clib_bihash_search_16_8 (&srm->ip4_reass_hash, &kv, &value))
{
- reass = 0;
- goto unlock;
+ if (value.value == (reass - srm->ip4_reass_pool))
+ {
+ if (clib_bihash_add_del_16_8 (&srm->ip4_reass_hash, &kv, 0))
+ {
+ reass = 0;
+ goto unlock;
+ }
+ }
}
nat_ip4_reass_get_frags_inline (reass, bi_to_drop);
n21'>21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
# Copyright (c) 2016 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Path utilities library for nodes in the topology."""

from resources.libraries.python.topology import Topology


class NodePath(object):
    """Path utilities for nodes in the topology.

    :Example:

    node1--link1-->node2--link2-->node3--link3-->node2--link4-->node1
    RobotFramework:
    | Library | resources/libraries/python/NodePath.py

    | Path test
    | | [Arguments] | ${node1} | ${node2} | ${node3}
    | | Append Node | ${nodes1}
    | | Append Node | ${nodes2}
    | | Append Nodes | ${nodes3} | ${nodes2}
    | | Append Node | ${nodes1}
    | | Compute Path | ${FALSE}
    | | ${first_int} | ${node}= | First Interface
    | | ${last_int} | ${node}= | Last Interface
    | | ${first_ingress} | ${node}= | First Ingress Interface
    | | ${last_egress} | ${node}= | Last Egress Interface
    | | ${next} | ${node}= | Next Interface

    Python:
    >>> from NodePath import NodePath
    >>> path = NodePath()
    >>> path.append_node(node1)
    >>> path.append_node(node2)
    >>> path.append_nodes(node3, node2)
    >>> path.append_node(node1)
    >>> path.compute_path()
    >>> (interface, node) = path.first_interface()
    >>> (interface, node) = path.last_interface()
    >>> (interface, node) = path.first_ingress_interface()
    >>> (interface, node) = path.last_egress_interface()
    >>> (interface, node) = path.next_interface()
    """

    def __init__(self):
        self._nodes = []
        self._nodes_filter = []
        self._links = []
        self._path = []
        self._path_iter = []

    def append_node(self, node, filter_list=None):
        """Append node to the path.

        :param node: Node to append to the path.
        :param filter_list: Filter criteria list.
        :type node: dict
        :type filter_list: list of strings
        """
        self._nodes_filter.append(filter_list)
        self._nodes.append(node)

    def append_nodes(self, *nodes):
        """Append nodes to the path.

        :param nodes: Nodes to append to the path.
        :type nodes: dict

        .. note:: Node order does matter.
        """
        for node in nodes:
            self.append_node(node)

    def clear_path(self):
        """Clear path."""
        self._nodes = []
        self._nodes_filter = []
        self._links = []
        self._path = []
        self._path_iter = []

    def compute_path(self, always_same_link=True):
        """Compute path for added nodes.

        :param always_same_link: If True use always same link between two nodes
        in path. If False use different link (if available) between two
        nodes if one link was used before.
        :type always_same_link: bool

        .. note:: First add at least two nodes to the topology.
        """
        nodes = self._nodes
        if len(nodes) < 2:
            raise RuntimeError('Not enough nodes to compute path')

        for idx in range(0, len(nodes) - 1):
            topo = Topology()
            node1 = nodes[idx]
            node2 = nodes[idx + 1]
            n1_list = self._nodes_filter[idx]
            n2_list = self._nodes_filter[idx + 1]
            links = topo.get_active_connecting_links(node1, node2,
                                                     filter_list_node1=n1_list,
                                                     filter_list_node2=n2_list)
            if not links:
                raise RuntimeError('No link between {0} and {1}'.format(
                    node1['host'], node2['host']))

            if always_same_link:
                l_set = set(links).intersection(self._links)
            else:
                l_set = set(links).difference(self._links)
                if not l_set:
                    raise RuntimeError(
                        'No free link between {0} and {1}, all links already '
                        'used'.format(node1['host'], node2['host']))

            if not l_set:
                link = links.pop()
            else:
                link = l_set.pop()

            self._links.append(link)
            interface1 = topo.get_interface_by_link_name(node1, link)
            interface2 = topo.get_interface_by_link_name(node2, link)
            self._path.append((interface1, node1))
            self._path.append((interface2, node2))

        self._path_iter.extend(self._path)
        self._path_iter.reverse()

    def next_interface(self):
        """Path interface iterator.

        :returns: Interface and node or None if not next interface.
        :rtype: tuple (str, dict)

        .. note:: Call compute_path before.
        """
        if not self._path_iter:
            return None, None
        else:
            return self._path_iter.pop()

    def first_interface(self):
        """Return first interface on the path.

        :returns: Interface and node.
        :rtype: tuple (str, dict)

        .. note:: Call compute_path before.
        """
        if not self._path:
            raise RuntimeError('No path for topology')
        return self._path[0]

    def last_interface(self):
        """Return last interface on the path.

        :returns: Interface and node.
        :rtype: tuple (str, dict)

        .. note:: Call compute_path before.
        """
        if not self._path:
            raise RuntimeError('No path for topology')
        return self._path[-1]

    def first_ingress_interface(self):
        """Return first ingress interface on the path.

        :returns: Interface and node.
        :rtype: tuple (str, dict)

        .. note:: Call compute_path before.
        """
        if not self._path:
            raise RuntimeError('No path for topology')
        return self._path[1]

    def last_egress_interface(self):
        """Return last egress interface on the path.

        :returns: Interface and node.
        :rtype: tuple (str, dict)

        .. note:: Call compute_path before.
        """
        if not self._path:
            raise RuntimeError('No path for topology')
        return self._path[-2]