use of org.batfish.datamodel.IpsecVpn in project batfish by batfish.
the class IpsecVpnStatusAnswerer method analyzeIpsecVpn.
@VisibleForTesting
public static IpsecVpnInfo analyzeIpsecVpn(IpsecVpn ipsecVpn) {
SortedSet<Problem> problems = new TreeSet<>();
IpsecVpn remoteIpsecVpn = null;
if (ipsecVpn.getRemoteIpsecVpn() == null) {
problems.add(Problem.MISSING_REMOTE_ENDPOINT);
} else {
if (ipsecVpn.getCandidateRemoteIpsecVpns().size() != 1) {
problems.add(Problem.MULTIPLE_REMOTE_ENDPOINTS);
}
remoteIpsecVpn = ipsecVpn.getRemoteIpsecVpn();
if (!ipsecVpn.compatibleIkeProposals(remoteIpsecVpn)) {
problems.add(Problem.INCOMPATIBLE_IKE_PROPOSALS);
}
if (!ipsecVpn.compatibleIpsecProposals(remoteIpsecVpn)) {
problems.add(Problem.INCOMPATIBLE_IPSEC_PROPOSALS);
}
if (!ipsecVpn.compatiblePreSharedKey(remoteIpsecVpn)) {
problems.add(Problem.INCOMPATIBLE_PRE_SHARED_KEY);
}
}
if (problems.size() == 0) {
problems.add(Problem.NONE);
}
return new IpsecVpnInfo(ipsecVpn, problems, remoteIpsecVpn);
}
use of org.batfish.datamodel.IpsecVpn in project batfish by batfish.
the class IpsecVpnStatusAnswerer method answer.
@Override
public AnswerElement answer() {
IpsecVpnStatusQuestion question = (IpsecVpnStatusQuestion) _question;
Map<String, Configuration> configurations = _batfish.loadConfigurations();
Set<String> includeNodes1 = question.getNode1Regex().getMatchingNodes(configurations);
Set<String> includeNodes2 = question.getNode2Regex().getMatchingNodes(configurations);
CommonUtil.initRemoteIpsecVpns(configurations);
IpsecVpnStatusAnswerElement answerElement = new IpsecVpnStatusAnswerElement();
for (Configuration c : configurations.values()) {
if (!includeNodes1.contains(c.getHostname())) {
continue;
}
for (IpsecVpn ipsecVpn : c.getIpsecVpns().values()) {
IpsecVpnInfo vpnInfo = analyzeIpsecVpn(ipsecVpn);
if ((vpnInfo.getRemoteEndpoint() == null || includeNodes2.contains(vpnInfo.getRemoteEndpoint().getHostname())) && vpnInfo.getProblems().stream().anyMatch(v -> question.matchesProblem(v))) {
answerElement.getIpsecVpns().add(vpnInfo);
}
}
}
return answerElement;
}
use of org.batfish.datamodel.IpsecVpn in project batfish by batfish.
the class IpsecVpnStatusAnswererTest method analyzeVpnTestIncompatibleIpsecProposal.
@Test
public void analyzeVpnTestIncompatibleIpsecProposal() {
IpsecVpn ipsecVpn = createIpsecVpn("local", IkeProposal.PSK_3DES_DH2_MD5, IpsecProposal.NOPFS_ESP_DES_MD5, "key");
IpsecVpn remote1 = createIpsecVpn("remote1", IkeProposal.PSK_3DES_DH2_MD5, IpsecProposal.NOPFS_ESP_DES_SHA, "key");
ipsecVpn.initCandidateRemoteVpns();
ipsecVpn.setRemoteIpsecVpn(remote1);
ipsecVpn.getCandidateRemoteIpsecVpns().add(remote1);
IpsecVpnInfo vpnInfo = IpsecVpnStatusAnswerer.analyzeIpsecVpn(ipsecVpn);
assertThat(vpnInfo.getProblems(), equalTo(Collections.singleton(Problem.INCOMPATIBLE_IPSEC_PROPOSALS)));
assertThat(vpnInfo.getRemoteEndpoint(), equalTo(new IpsecVpnEndpoint(remote1)));
}
use of org.batfish.datamodel.IpsecVpn in project batfish by batfish.
the class IpsecVpnStatusAnswererTest method createIpsecVpn.
private static IpsecVpn createIpsecVpn(String name, IkeProposal ikeProposal, IpsecProposal ipsecProposal, String pskHash) {
IpsecVpn ipsecVpn = new IpsecVpn(name);
ipsecVpn.setOwner(new Configuration(name, ConfigurationFormat.UNKNOWN));
IkeGateway ikeGw = new IkeGateway(name + "-ikeGw");
ipsecVpn.setIkeGateway(ikeGw);
IkePolicy ikePolicy = new IkePolicy(name + "-ikePolicy");
ikeGw.setIkePolicy(ikePolicy);
SortedMap<String, IkeProposal> ikeProposalMap = new TreeMap<>();
ikeProposalMap.put(name + "-ikeproposal", ikeProposal);
ikePolicy.setProposals(ikeProposalMap);
ikePolicy.setPreSharedKeyHash(pskHash);
IpsecPolicy ipsecPolicy = new IpsecPolicy(name + "-ipsecpolicy");
ipsecVpn.setIpsecPolicy(ipsecPolicy);
SortedMap<String, IpsecProposal> ipsecProposalMap = new TreeMap<>();
ipsecProposalMap.put(name + "-ipsecproposal", ipsecProposal);
ipsecPolicy.setProposals(ipsecProposalMap);
return ipsecVpn;
}
use of org.batfish.datamodel.IpsecVpn in project batfish by batfish.
the class IpsecVpnStatusAnswererTest method analyzeVpnTestIncompatiblePreSharedKey.
@Test
public void analyzeVpnTestIncompatiblePreSharedKey() {
IpsecVpn ipsecVpn = createIpsecVpn("local", IkeProposal.PSK_3DES_DH2_MD5, IpsecProposal.NOPFS_ESP_DES_MD5, "key");
IpsecVpn remote1 = createIpsecVpn("remote1", IkeProposal.PSK_3DES_DH2_MD5, IpsecProposal.NOPFS_ESP_DES_MD5, "key-bad");
ipsecVpn.initCandidateRemoteVpns();
ipsecVpn.setRemoteIpsecVpn(remote1);
ipsecVpn.getCandidateRemoteIpsecVpns().add(remote1);
IpsecVpnInfo vpnInfo = IpsecVpnStatusAnswerer.analyzeIpsecVpn(ipsecVpn);
assertThat(vpnInfo.getProblems(), equalTo(Collections.singleton(Problem.INCOMPATIBLE_PRE_SHARED_KEY)));
assertThat(vpnInfo.getRemoteEndpoint(), equalTo(new IpsecVpnEndpoint(remote1)));
}
Aggregations