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;
}
Aggregations