diff --git a/app/src/main/java/ru/kirillius/pf/sdn/External/API/Components/ROS.java b/app/src/main/java/ru/kirillius/pf/sdn/External/API/Components/ROS.java index f07f08a..5f27bfa 100644 --- a/app/src/main/java/ru/kirillius/pf/sdn/External/API/Components/ROS.java +++ b/app/src/main/java/ru/kirillius/pf/sdn/External/API/Components/ROS.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; /** @@ -35,6 +36,33 @@ public final class ROS extends AbstractComponent { subscription = context.getEventsHandler().getNetworkManagerUpdateEvent().add(bundle -> updateSubnets(bundle.getSubnets())); } + public List> getRoutesByGatewayAndVRF(ApiConnection connection, String gateway, String vrf) + throws MikrotikApiException { + + List> allRoutes = new ArrayList<>(); + int offset = 0; + final int LIMIT = 100; + +// while (true) { +// // Формируем запрос с пагинацией. Каждый параметр - отдельный аргумент. +// List> chunk = connection.execute( +// "/ip/route/print", +// "gateway=" + gateway, +// "routing-table=" + vrf, +// ".proplist=.id,dst-address,static", // Указываем нужные поля +// "limit=" + offset + "," + LIMIT +// ); +// +// if (chunk == null || chunk.isEmpty()) { +// break; // Выходим из цикла, если данных больше нет +// } +// +// allRoutes.addAll(chunk); +// offset += LIMIT; // Переходим к следующей порции +// } + return allRoutes; + } + /** * Synchronises FRR instances with the provided subnet list. */ @@ -46,9 +74,9 @@ public final class ROS extends AbstractComponent { connection.login(entry.username, entry.password); SystemLogger.message("Fetching existing subnets...", CTX); var existingSubnets = new HashMap(); - var result = connection.execute("/ip/route/print where gateway=" + entry.gateway + " and routing-table=" + entry.VRF); + var result = connection.execute("/ip/route/print .proplist=.id,dst-address,static,gateway where static=true and routing-table=" + entry.VRF); result.forEach(row -> { - if (row.containsKey("static") && row.get("static").equals("true")) { + if (row.containsKey("static") && row.get("gateway").contains(entry.gateway)) { existingSubnets.put(row.get(".id"), new IPv4Subnet(row.get("dst-address"))); } }); @@ -85,7 +113,7 @@ public final class ROS extends AbstractComponent { try { connection.execute("/ip/route/add dst-address=" + subnet + " gateway=" + entry.gateway + " routing-table=" + entry.VRF); counter.incrementAndGet(); - if(counter.get() % 100 == 0){ + if (counter.get() % 100 == 0) { SystemLogger.message(counter.get() + " subnets has been added", CTX); } } catch (MikrotikApiException e) { diff --git a/pom.xml b/pom.xml index 8a24fda..b0bcb33 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ me.legrange mikrotik - 3.0.8 + 3.0.8.1