Search in sources :

Example 1 with Direction

use of org.batfish.datamodel.routing_policy.Environment.Direction in project batfish by batfish.

the class AutoAs method evaluate.

@Override
public int evaluate(Environment environment) {
    BgpProcess proc = environment.getVrf().getBgpProcess();
    if (proc == null) {
        throw new BatfishException("Expected BGP process");
    }
    Direction direction = environment.getDirection();
    int as;
    Ip peerAddress = environment.getPeerAddress();
    if (peerAddress == null) {
        throw new BatfishException("Expected a peer address");
    }
    Prefix peerPrefix = new Prefix(peerAddress, Prefix.MAX_PREFIX_LENGTH);
    BgpNeighbor neighbor = proc.getNeighbors().get(peerPrefix);
    if (neighbor == null) {
        throw new BatfishException("Expected a peer with address: " + peerAddress);
    }
    if (direction == Direction.IN) {
        as = neighbor.getRemoteAs();
    } else if (direction == Direction.OUT) {
        as = neighbor.getLocalAs();
    } else {
        throw new BatfishException("Expected to be applied in a direction");
    }
    return as;
}
Also used : BgpNeighbor(org.batfish.datamodel.BgpNeighbor) BatfishException(org.batfish.common.BatfishException) BgpProcess(org.batfish.datamodel.BgpProcess) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) Direction(org.batfish.datamodel.routing_policy.Environment.Direction)

Aggregations

BatfishException (org.batfish.common.BatfishException)1 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)1 BgpProcess (org.batfish.datamodel.BgpProcess)1 Ip (org.batfish.datamodel.Ip)1 Prefix (org.batfish.datamodel.Prefix)1 Direction (org.batfish.datamodel.routing_policy.Environment.Direction)1