corefx - fixed some issues loading xml due to grpc change, updated subnet logic to help handle loaded scenarios. grpc - fixed issue when loading network links
This commit is contained in:
parent
338439b429
commit
0af3629ac6
4 changed files with 42 additions and 20 deletions
|
@ -73,11 +73,9 @@ public class NodeType {
|
||||||
return ID_LOOKUP.values().stream()
|
return ID_LOOKUP.values().stream()
|
||||||
.filter(nodeType -> {
|
.filter(nodeType -> {
|
||||||
boolean sameType = nodeType.getValue() == type;
|
boolean sameType = nodeType.getValue() == type;
|
||||||
boolean sameModel;
|
boolean sameModel = true;
|
||||||
if (model != null) {
|
if (!model.isEmpty()) {
|
||||||
sameModel = model.equals(nodeType.getModel());
|
sameModel = model.equals(nodeType.getModel());
|
||||||
} else {
|
|
||||||
sameModel = nodeType.getModel() == null;
|
|
||||||
}
|
}
|
||||||
return sameType && sameModel;
|
return sameType && sameModel;
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,9 @@ import inet.ipaddr.IPAddressString;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.beans.IndexedPropertyDescriptor;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
@ -16,8 +18,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
public class CoreAddresses {
|
public class CoreAddresses {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
private IPAddress currentSubnet = new IPAddressString("10.0.0.0/24").getAddress().toPrefixBlock();
|
private IPAddress currentSubnet = new IPAddressString("10.0.0.0/24").getAddress().toPrefixBlock();
|
||||||
private AtomicBoolean firstSubnet = new AtomicBoolean(true);
|
|
||||||
private Queue<IPAddress> deleted = new LinkedBlockingQueue<>();
|
private Queue<IPAddress> deleted = new LinkedBlockingQueue<>();
|
||||||
|
private Set<IPAddress> usedSubnets = new HashSet<>();
|
||||||
|
|
||||||
|
public void usedAddress(IPAddress address) {
|
||||||
|
logger.info("adding used address: {} - {}", address, address.toPrefixBlock());
|
||||||
|
usedSubnets.add(address.toPrefixBlock());
|
||||||
|
logger.info("used subnets: {}", usedSubnets);
|
||||||
|
}
|
||||||
|
|
||||||
public void reuseSubnet(IPAddress subnet) {
|
public void reuseSubnet(IPAddress subnet) {
|
||||||
deleted.add(subnet);
|
deleted.add(subnet);
|
||||||
|
@ -25,16 +33,18 @@ public class CoreAddresses {
|
||||||
|
|
||||||
public IPAddress nextSubnet() {
|
public IPAddress nextSubnet() {
|
||||||
logger.info("getting next subnet: {}", currentSubnet);
|
logger.info("getting next subnet: {}", currentSubnet);
|
||||||
if (!firstSubnet.getAndSet(false)) {
|
// skip existing subnets, when loaded from file
|
||||||
IPAddress deletedSubnet = deleted.poll();
|
while (usedSubnets.contains(currentSubnet)) {
|
||||||
if (deletedSubnet != null) {
|
|
||||||
currentSubnet = deletedSubnet;
|
|
||||||
} else {
|
|
||||||
currentSubnet = currentSubnet.incrementBoundary(1).toPrefixBlock();
|
currentSubnet = currentSubnet.incrementBoundary(1).toPrefixBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// re-use any deleted subnets
|
||||||
|
IPAddress next = deleted.poll();
|
||||||
|
if (next == null) {
|
||||||
|
next = currentSubnet;
|
||||||
|
currentSubnet = currentSubnet.incrementBoundary(1).toPrefixBlock();
|
||||||
}
|
}
|
||||||
logger.info("getting updated boundary: {}", currentSubnet);
|
return next;
|
||||||
return currentSubnet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPAddress findSubnet(Set<CoreInterface> interfaces) {
|
public IPAddress findSubnet(Set<CoreInterface> interfaces) {
|
||||||
|
@ -58,7 +68,7 @@ public class CoreAddresses {
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
deleted.clear();
|
deleted.clear();
|
||||||
firstSubnet.set(true);
|
usedSubnets.clear();
|
||||||
currentSubnet = new IPAddressString("10.0.0.0/24").getAddress().toPrefixBlock();
|
currentSubnet = new IPAddressString("10.0.0.0/24").getAddress().toPrefixBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,13 @@ public class NetworkGraph {
|
||||||
private void handleEdgeAdded(GraphEvent.Edge<CoreNode, CoreLink> edgeEvent) {
|
private void handleEdgeAdded(GraphEvent.Edge<CoreNode, CoreLink> edgeEvent) {
|
||||||
CoreLink link = edgeEvent.getEdge();
|
CoreLink link = edgeEvent.getEdge();
|
||||||
if (link.isLoaded()) {
|
if (link.isLoaded()) {
|
||||||
|
// load addresses to avoid duplication
|
||||||
|
if (link.getInterfaceOne().getIp4() != null) {
|
||||||
|
coreAddresses.usedAddress(link.getInterfaceOne().getIp4());
|
||||||
|
}
|
||||||
|
if (link.getInterfaceTwo().getIp4() != null) {
|
||||||
|
coreAddresses.usedAddress(link.getInterfaceTwo().getIp4());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pair<CoreNode> endpoints = graph.getEndpoints(link);
|
Pair<CoreNode> endpoints = graph.getEndpoints(link);
|
||||||
|
@ -508,7 +515,7 @@ public class NetworkGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWirelessNode(CoreNode node) {
|
private boolean isWirelessNode(CoreNode node) {
|
||||||
return node.getType() == NodeType.EMANE || node.getType() == NodeType.WLAN;
|
return node != null && (node.getType() == NodeType.EMANE || node.getType() == NodeType.WLAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkForWirelessNode(CoreNode nodeOne, CoreNode nodeTwo) {
|
private boolean checkForWirelessNode(CoreNode nodeOne, CoreNode nodeTwo) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ from core.emulator.emudata import NodeOptions, InterfaceData, LinkOptions
|
||||||
from core.emulator.enumerations import NodeTypes, EventTypes, LinkTypes
|
from core.emulator.enumerations import NodeTypes, EventTypes, LinkTypes
|
||||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||||
from core.nodes import nodeutils
|
from core.nodes import nodeutils
|
||||||
|
from core.nodes.base import CoreNetworkBase
|
||||||
from core.nodes.ipaddress import MacAddress
|
from core.nodes.ipaddress import MacAddress
|
||||||
from core.services.coreservices import ServiceManager
|
from core.services.coreservices import ServiceManager
|
||||||
|
|
||||||
|
@ -73,18 +74,24 @@ def convert_link(session, link_data):
|
||||||
interface_one = None
|
interface_one = None
|
||||||
if link_data.interface1_id is not None:
|
if link_data.interface1_id is not None:
|
||||||
node = session.get_node(link_data.node1_id)
|
node = session.get_node(link_data.node1_id)
|
||||||
|
interface_name = None
|
||||||
|
if not isinstance(node, CoreNetworkBase):
|
||||||
interface = node.netif(link_data.interface1_id)
|
interface = node.netif(link_data.interface1_id)
|
||||||
|
interface_name = interface.name
|
||||||
interface_one = core_pb2.Interface(
|
interface_one = core_pb2.Interface(
|
||||||
id=link_data.interface1_id, name=interface.name, mac=convert_value(link_data.interface1_mac),
|
id=link_data.interface1_id, name=interface_name, mac=convert_value(link_data.interface1_mac),
|
||||||
ip4=convert_value(link_data.interface1_ip4), ip4mask=link_data.interface1_ip4_mask,
|
ip4=convert_value(link_data.interface1_ip4), ip4mask=link_data.interface1_ip4_mask,
|
||||||
ip6=convert_value(link_data.interface1_ip6), ip6mask=link_data.interface1_ip6_mask)
|
ip6=convert_value(link_data.interface1_ip6), ip6mask=link_data.interface1_ip6_mask)
|
||||||
|
|
||||||
interface_two = None
|
interface_two = None
|
||||||
if link_data.interface2_id is not None:
|
if link_data.interface2_id is not None:
|
||||||
node = session.get_node(link_data.node2_id)
|
node = session.get_node(link_data.node2_id)
|
||||||
|
interface_name = None
|
||||||
|
if not isinstance(node, CoreNetworkBase):
|
||||||
interface = node.netif(link_data.interface2_id)
|
interface = node.netif(link_data.interface2_id)
|
||||||
|
interface_name = interface.name
|
||||||
interface_two = core_pb2.Interface(
|
interface_two = core_pb2.Interface(
|
||||||
id=link_data.interface2_id, name=interface.name, mac=convert_value(link_data.interface2_mac),
|
id=link_data.interface2_id, name=interface_name, mac=convert_value(link_data.interface2_mac),
|
||||||
ip4=convert_value(link_data.interface2_ip4), ip4mask=link_data.interface2_ip4_mask,
|
ip4=convert_value(link_data.interface2_ip4), ip4mask=link_data.interface2_ip4_mask,
|
||||||
ip6=convert_value(link_data.interface2_ip6), ip6mask=link_data.interface2_ip6_mask)
|
ip6=convert_value(link_data.interface2_ip6), ip6mask=link_data.interface2_ip6_mask)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue