fixed RouterOS API issues
This commit is contained in:
parent
3683dde410
commit
a23b915f61
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,6 +36,33 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
||||||
subscription = context.getEventsHandler().getNetworkManagerUpdateEvent().add(bundle -> updateSubnets(bundle.getSubnets()));
|
subscription = context.getEventsHandler().getNetworkManagerUpdateEvent().add(bundle -> updateSubnets(bundle.getSubnets()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Map<String, String>> getRoutesByGatewayAndVRF(ApiConnection connection, String gateway, String vrf)
|
||||||
|
throws MikrotikApiException {
|
||||||
|
|
||||||
|
List<Map<String, String>> allRoutes = new ArrayList<>();
|
||||||
|
int offset = 0;
|
||||||
|
final int LIMIT = 100;
|
||||||
|
|
||||||
|
// while (true) {
|
||||||
|
// // Формируем запрос с пагинацией. Каждый параметр - отдельный аргумент.
|
||||||
|
// List<Map<String, String>> 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.
|
* Synchronises FRR instances with the provided subnet list.
|
||||||
*/
|
*/
|
||||||
|
|
@ -46,9 +74,9 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
||||||
connection.login(entry.username, entry.password);
|
connection.login(entry.username, entry.password);
|
||||||
SystemLogger.message("Fetching existing subnets...", CTX);
|
SystemLogger.message("Fetching existing subnets...", CTX);
|
||||||
var existingSubnets = new HashMap<String, IPv4Subnet>();
|
var existingSubnets = new HashMap<String, IPv4Subnet>();
|
||||||
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 -> {
|
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")));
|
existingSubnets.put(row.get(".id"), new IPv4Subnet(row.get("dst-address")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -85,7 +113,7 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
||||||
try {
|
try {
|
||||||
connection.execute("/ip/route/add dst-address=" + subnet + " gateway=" + entry.gateway + " routing-table=" + entry.VRF);
|
connection.execute("/ip/route/add dst-address=" + subnet + " gateway=" + entry.gateway + " routing-table=" + entry.VRF);
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if(counter.get() % 100 == 0){
|
if (counter.get() % 100 == 0) {
|
||||||
SystemLogger.message(counter.get() + " subnets has been added", CTX);
|
SystemLogger.message(counter.get() + " subnets has been added", CTX);
|
||||||
}
|
}
|
||||||
} catch (MikrotikApiException e) {
|
} catch (MikrotikApiException e) {
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -82,7 +82,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.legrange</groupId>
|
<groupId>me.legrange</groupId>
|
||||||
<artifactId>mikrotik</artifactId>
|
<artifactId>mikrotik</artifactId>
|
||||||
<version>3.0.8</version>
|
<version>3.0.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue