diff --git a/cfg/mpls-te14.tst b/cfg/mpls-te14.tst index 9eb8b722cb..feec1a8adb 100644 --- a/cfg/mpls-te14.tst +++ b/cfg/mpls-te14.tst @@ -187,11 +187,11 @@ r3 tping 100 10 4321::1 /vrf v1 /int lo0 r3 tping 100 10 2.2.2.2 /vrf v1 /int lo0 r3 tping 100 10 4321::2 /vrf v1 /int lo0 -r1 tping 100 10 3.3.3.1 /vrf v1 /int lo0 -r1 tping 100 10 3.3.3.2 /vrf v1 /int lo0 -r1 tping 100 10 3.3.3.3 /vrf v1 /int lo0 -r1 tping 100 10 3.3.3.4 /vrf v1 /int lo0 -r1 tping 100 10 3333::1 /vrf v1 /int lo0 -r1 tping 100 10 3333::2 /vrf v1 /int lo0 -r1 tping 100 10 3333::3 /vrf v1 /int lo0 -r1 tping 100 10 3333::4 /vrf v1 /int lo0 +r1 tping 100 10 3.3.3.1 /vrf v1 /int lo0 /multi +r1 tping 100 10 3.3.3.2 /vrf v1 /int lo0 /multi +r1 tping 100 10 3.3.3.3 /vrf v1 /int lo0 /multi +r1 tping 300 10 3.3.3.4 /vrf v1 /int lo0 /multi +r1 tping 100 10 3333::1 /vrf v1 /int lo0 /multi +r1 tping 100 10 3333::2 /vrf v1 /int lo0 /multi +r1 tping 100 10 3333::3 /vrf v1 /int lo0 /multi +r1 tping 300 10 3333::4 /vrf v1 /int lo0 /multi diff --git a/src/net/freertr/addr/addrType.java b/src/net/freertr/addr/addrType.java index a395188689..8560813682 100644 --- a/src/net/freertr/addr/addrType.java +++ b/src/net/freertr/addr/addrType.java @@ -296,10 +296,10 @@ public void setNot(addrType a1) { } /** - * set from not a1 + * set from shifted a1 * * @param a1 address - * @param sh shift + * @param shf shift */ public void setShl(addrType a1, int shf) { int shb = shf / 8; diff --git a/src/net/freertr/tab/tabGep.java b/src/net/freertr/tab/tabGep.java new file mode 100644 index 0000000000..3e754b9b2e --- /dev/null +++ b/src/net/freertr/tab/tabGep.java @@ -0,0 +1,20 @@ +package net.freertr.tab; + +import net.freertr.addr.addrType; + +/** + * one prefix tree + * + * @param type of elements in the list + * @author matecsaba + */ +public class tabGep extends tabGepV2 { + + /** + * create one generic tree + */ + public tabGep() { + super(); + } + +} diff --git a/src/net/freertr/tab/tabGepV1.java b/src/net/freertr/tab/tabGepV1.java new file mode 100644 index 0000000000..3747af9ca0 --- /dev/null +++ b/src/net/freertr/tab/tabGepV1.java @@ -0,0 +1,79 @@ +package net.freertr.tab; + +import java.util.Map; +import java.util.TreeMap; +import net.freertr.addr.addrPrefix; +import net.freertr.addr.addrType; + +/** + * one prefix tree + * + * @param type of elements in the list + * @author matecsaba + */ +public class tabGepV1 { + + private TreeMap, tabRouteEntry> tree; + + /** + * create one generic tree + */ + public tabGepV1() { + tree = new TreeMap, tabRouteEntry>(); + } + + /** + * add one entry + * + * @param val value to add + * @return old value, null if freshly added + */ + public tabRouteEntry add(tabRouteEntry val) { + return tree.put(new tabGepV1nod(val), val); + } + + /** + * add one entry + * + * @param val value to add + * @return removed value, null if not found + */ + public tabRouteEntry del(tabRouteEntry val) { + return tree.remove(new tabGepV1nod(val)); + } + + /** + * find one container entry + * + * @param val value to look up + * @return found value + */ + public tabRouteEntry search(tabRouteEntry val) { + Map.Entry, tabRouteEntry> res = tree.floorEntry(new tabGepV1nod(val)); + for (;;) { + if (res == null) { + return null; + } + tabRouteEntry v = res.getValue(); + if (v.prefix.supernet(val.prefix, true)) { + return v; + } + res = tree.lowerEntry(res.getKey()); + } + } + +} + +class tabGepV1nod implements Comparable> { + + public addrPrefix pfx; + + public tabGepV1nod(tabRouteEntry val) { + pfx = val.prefix; + } + + public int compareTo(tabGepV1nod o) { + return pfx.compare(pfx, o.pfx); + } + +} diff --git a/src/net/freertr/tab/tabGepV2.java b/src/net/freertr/tab/tabGepV2.java new file mode 100644 index 0000000000..ef5547232e --- /dev/null +++ b/src/net/freertr/tab/tabGepV2.java @@ -0,0 +1,124 @@ +package net.freertr.tab; + +import net.freertr.addr.addrType; + +/** + * one prefix tree + * + * @param type of elements in the list + * @author matecsaba + */ +public class tabGepV2 { + + private tabGepV2nod rot; + + /** + * create one generic tree + */ + public tabGepV2() { + rot = new tabGepV2nod(); + } + + /** + * add one entry + * + * @param val value to add + * @return old value, null if freshly added + */ + public tabRouteEntry add(tabRouteEntry val) { + tabGepV2nod cur = rot; + for (int p = 0;; p++) { + if (p >= val.prefix.maskLen) { + tabRouteEntry old = cur.val; + cur.val = val; + return old; + } + if (val.prefix.network.bitValue(p)) { + if (cur.one == null) { + cur.one = new tabGepV2nod(); + } + cur = cur.one; + } else { + if (cur.zero == null) { + cur.zero = new tabGepV2nod(); + } + cur = cur.zero; + } + } + } + + /** + * add one entry + * + * @param val value to add + * @return removed value, null if not found + */ + public tabRouteEntry del(tabRouteEntry val) { + tabGepV2nod cur = rot; + for (int p = 0;; p++) { + if (p >= val.prefix.maskLen) { + tabRouteEntry old = cur.val; + cur.val = null; + return old; + } + if (val.prefix.network.bitValue(p)) { + if (cur.one == null) { + return null; + } + cur = cur.one; + } else { + if (cur.zero == null) { + return null; + } + cur = cur.zero; + } + } + } + + /** + * find one container entry + * + * @param val value to look up + * @return found value + */ + public tabRouteEntry search(tabRouteEntry val) { + tabGepV2nod cur = rot; + tabRouteEntry lst = null; + for (int p = 0;; p++) { + if (cur.val != null) { + lst = cur.val; + } + if (p >= val.prefix.maskLen) { + return lst; + } + if (val.prefix.network.bitValue(p)) { + if (cur.one == null) { + return lst; + } + cur = cur.one; + } else { + if (cur.zero == null) { + return lst; + } + cur = cur.zero; + } + } + } + +} + +class tabGepV2nod { + + public tabGepV2nod zero; + + public tabGepV2nod one; + + public tabRouteEntry val; + + public tabGepV2nod() { + val = null; + zero = null; + one = null; + } + +} diff --git a/src/net/freertr/tab/tabRoute.java b/src/net/freertr/tab/tabRoute.java index 6b54f95bc6..908cd2afd7 100644 --- a/src/net/freertr/tab/tabRoute.java +++ b/src/net/freertr/tab/tabRoute.java @@ -81,6 +81,8 @@ public enum addType { */ protected final tabGen> prefixes; + private tabGep lookupTrie = null; + /** * version of this table */ @@ -123,7 +125,11 @@ public tabRoute(tabRoute orig) { * optimize for lookup */ public void optimize4lookup() { - prefixes.optimize4lookup(); + tabGep res = new tabGep(); + for (int i = 0; i < prefixes.size(); i++) { + res.add(prefixes.get(i)); + } + lookupTrie = res; } /** @@ -638,6 +644,9 @@ private boolean doNexthopFix(tabRouteAttr attr, tabRoute recurs, int recur public tabRouteEntry route(T addr) { tabRouteEntry prf = new tabRouteEntry(); prf.prefix = new addrPrefix(addr, addr.maxBits()); + if (lookupTrie != null) { + return lookupTrie.search(prf); + } for (int o = prf.prefix.maskLen; o >= 0; o--) { prf.prefix.setMask(o); tabRouteEntry res = prefixes.find(prf); diff --git a/src/rtr.csv b/src/rtr.csv index 9647116a18..ae7adce7ed 100644 --- a/src/rtr.csv +++ b/src/rtr.csv @@ -1,6 +1,6 @@ url;file;result;test -;-;-;freeRouter v21.12.29-cur, done by cs@nop. --;-;-;2021-12-29 05:09:51, took 00:06:31, with 100 workers, on 2520 cases, 0 failed, 0 traces, 1 retries +-;-;-;2021-12-29 08:23:09, took 00:06:43, with 100 workers, on 2520 cases, 0 failed, 0 traces, 3 retries -;-;-;./rtr.bin http://sources.nop.hu/cfg/basic.tst;basic.tst;success;dummy test http://sources.nop.hu/cfg/conn-amt01.tst;conn-amt01.tst;success;amt over ipv4 diff --git a/src/rtr.html b/src/rtr.html index 7518eef0fd..150a87b9c9 100644 --- a/src/rtr.html +++ b/src/rtr.html @@ -11,7 +11,7 @@ tester release: freeRouter v21.12.29-cur, done by cs@nop.
-tested: 2021-12-29 05:09:51, took 00:06:31, with 100 workers, on 2520 cases, 0 failed, 0 traces, 1 retries
+tested: 2021-12-29 08:23:09, took 00:06:43, with 100 workers, on 2520 cases, 0 failed, 0 traces, 3 retries
jvm: ./rtr.bin

fileresulttest