Search in sources :

Example 1 with NodeDevice

use of org.batfish.representation.juniper.NodeDevice in project batfish by batfish.

the class ConfigurationBuilder method enterInt_named.

@Override
public void enterInt_named(Int_namedContext ctx) {
    Interface currentInterface;
    if (ctx.interface_id() == null) {
        currentInterface = _configuration.getGlobalMasterInterface();
    } else {
        String ifaceName = getInterfaceName(ctx.interface_id());
        Map<String, Interface> interfaces;
        String nodeDevicePrefix = "";
        if (ctx.interface_id().node == null) {
            interfaces = _configuration.getInterfaces();
        } else {
            String nodeDeviceName = ctx.interface_id().node.getText();
            nodeDevicePrefix = nodeDeviceName + ":";
            NodeDevice nodeDevice = _configuration.getNodeDevices().computeIfAbsent(nodeDeviceName, NodeDevice::new);
            interfaces = nodeDevice.getInterfaces();
        }
        currentInterface = interfaces.get(ifaceName);
        if (currentInterface == null) {
            String fullIfaceName = nodeDevicePrefix + ifaceName;
            int definitionLine = ctx.interface_id().getStart().getLine();
            currentInterface = new Interface(fullIfaceName, definitionLine);
            currentInterface.setRoutingInstance(_currentRoutingInstance.getName());
            currentInterface.setParent(_configuration.getGlobalMasterInterface());
            interfaces.put(fullIfaceName, currentInterface);
        }
    }
    _currentInterface = currentInterface;
    _currentMasterInterface = currentInterface;
}
Also used : PsFromInterface(org.batfish.representation.juniper.PsFromInterface) Interface(org.batfish.representation.juniper.Interface) NodeDevice(org.batfish.representation.juniper.NodeDevice)

Example 2 with NodeDevice

use of org.batfish.representation.juniper.NodeDevice in project batfish by batfish.

the class ConfigurationBuilder method initInterface.

private Interface initInterface(Interface_idContext id) {
    String currentRoutingInstance = _currentRoutingInstance.getName();
    Map<String, Interface> interfaces;
    if (id.node != null) {
        String nodeDeviceName = id.node.getText();
        NodeDevice nodeDevice = _configuration.getNodeDevices().computeIfAbsent(nodeDeviceName, NodeDevice::new);
        interfaces = nodeDevice.getInterfaces();
    } else {
        interfaces = _configuration.getInterfaces();
    }
    String name = getInterfaceName(id);
    int definitionLine = id.name.getLine();
    String unit = null;
    if (id.unit != null) {
        unit = id.unit.getText();
        definitionLine = id.unit.getLine();
    }
    String unitFullName = name + "." + unit;
    Interface iface = interfaces.get(name);
    if (iface == null) {
        iface = new Interface(name, definitionLine);
        iface.setRoutingInstance(currentRoutingInstance);
        interfaces.put(name, iface);
    }
    if (unit != null) {
        Map<String, Interface> units = iface.getUnits();
        iface = units.get(unitFullName);
        if (iface == null) {
            iface = new Interface(unitFullName, definitionLine);
            iface.setRoutingInstance(currentRoutingInstance);
            units.put(unitFullName, iface);
        }
    }
    return iface;
}
Also used : PsFromInterface(org.batfish.representation.juniper.PsFromInterface) Interface(org.batfish.representation.juniper.Interface) NodeDevice(org.batfish.representation.juniper.NodeDevice)

Aggregations

Interface (org.batfish.representation.juniper.Interface)2 NodeDevice (org.batfish.representation.juniper.NodeDevice)2 PsFromInterface (org.batfish.representation.juniper.PsFromInterface)2