class IpsecUtil {

  @VisibleForTesting
  @Nonnull
  static IpsecSession getIpsecSession(
      Configuration initiatorOwner,
      Configuration peerOwner,
      IpsecStaticPeerConfig initiator,
      IpsecPeerConfig candidatePeer) {
    IpsecSession.Builder ipsecSessionBuilder = IpsecSession.builder();

    ipsecSessionBuilder.setCloud(
        IpsecSession.isCloudConfig(initiatorOwner) || IpsecSession.isCloudConfig(peerOwner));

    negotiateIkeP1(initiatorOwner, peerOwner, initiator, candidatePeer, ipsecSessionBuilder);

    if (ipsecSessionBuilder.getNegotiatedIkeP1Proposal() == null
        || ipsecSessionBuilder.getNegotiatedIkeP1Key() == null) {
      return ipsecSessionBuilder.build();
    }

    negotiateIpsecP2(initiatorOwner, peerOwner, initiator, candidatePeer, ipsecSessionBuilder);

    return ipsecSessionBuilder.build();
  }

}