diff --git a/src/lib/orderman/actors/ilink3/ILinkGW.cpp b/src/lib/orderman/actors/ilink3/ILinkGW.cpp index 435af91d3..9299083a8 100644 --- a/src/lib/orderman/actors/ilink3/ILinkGW.cpp +++ b/src/lib/orderman/actors/ilink3/ILinkGW.cpp @@ -69,7 +69,7 @@ ILinkGW::ILinkGW(IL3Connection& con, const Session& session, const Config& conf) } void ILinkGW::connect() { - bts_assert(state() == State::INIT); + bts_assert(state() == State::INIT || state() == State::ERROR); set_state(State::CONNECTING); _connection.connect(*this); // -> on_connect_success } @@ -393,14 +393,13 @@ void ILinkGW::handle(const iLinkBinary::NegotiationResponse501& msg) { auto cme_prev_uuid = msg.previousUUID(); auto cme_prev_seq = msg.previousSeqNo(); // Check if cme sent us a previous session - if (cme_prev_uuid != iLinkBinary::NegotiationResponse501::previousUUIDNullValue()) { - auto my_session = _config.previous_session; - if (my_session.uuid == cme_prev_uuid) { + if (cme_prev_uuid != iLinkBinary::NegotiationResponse501::previousUUIDNullValue() && cme_prev_seq > 0) { + if (_config.previous_session.uuid == cme_prev_uuid) { // There is a previous session and we knew about it // Replay any missing messages - if (my_session.from_sequence < cme_prev_seq) { + if (_config.previous_session.from_sequence < cme_prev_seq) { set_state(State::RETRANSMISSING_LAST); - send_retransmit_request(cme_prev_uuid, my_session.from_sequence); + send_retransmit_request(cme_prev_uuid, _config.previous_session.from_sequence); } else { // There is a previous session but we didn't miss anything diff --git a/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h b/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h index 7abc433da..838a7c41f 100644 --- a/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h +++ b/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h @@ -68,6 +68,7 @@ struct ExchangeOrder { struct TestExchangeConfig { bool reject_negotiate; std::string expected_firm; + bool reject_establish_on_primary; }; struct IL3TestExchange { @@ -114,6 +115,13 @@ struct IL3TestExchange { }); } + // void terminate() { + // auto t = buffer.frame(); + // t.uUID(this->session); + // respond("<- Terminate"); + // work.push([=]() { connection.disconnect(); }); + // } + void log(const std::string& s) { msg_log += s; msg_log += " "; } void handle(const iLinkBinary::Negotiate500& n) { @@ -142,6 +150,11 @@ struct IL3TestExchange { resp.putReason("Session doesn't match"); respond("<- EstablishmentReject"); } + else if (this->config.reject_establish_on_primary && !connection.is_backup) { + auto resp = buffer.frame(); + resp.putReason("Gateway down"); + respond("<- EstablishmentReject"); + } else { this->expected_seq = msg.nextSeqNo(); auto resp = buffer.frame(); diff --git a/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp b/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp index a0ebfcfa1..5ec385e27 100644 --- a/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp +++ b/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp @@ -218,18 +218,20 @@ TEST_CASE("EstablishExistingSession", "[ilink3]") { auto& connection = exchange.connect(); // New session starts at 1 Session session = Session::create(); + // Set the exchange to know about our session + exchange.session = session.uuid; Config config { Session::none(), "NGG", "004", false }; ILinkGW gw { connection, session, config }; - gw.connect(); exchange.do_work(); - // todo: establish without negotiate + REQUIRE(exchange.session == session.uuid); + REQUIRE(exchange.expected_seq == session.to_sequence); + REQUIRE(exchange.msg_log == "-> Establish <- EstablishAck -> Sequence <- Sequence "); } // -// TODO: -// Add certification tests here +// Certification tests here // https://www.cmegroup.com/tools-information/webhelp/autocert-ilink/Content/ACPiLinkUserManual.pdf // @@ -253,6 +255,18 @@ TEST_CASE("BeginningOfWeekLogon", "[ilink3][cert]") { TEST_CASE("PrimaryGatewayConnectionEnforcement", "[ilink3][il3cert]") { + IL3TestExchange exchange; + auto& connection = exchange.connect(); + Session session = Session::create(); + exchange.session = session.uuid; + exchange.config.reject_establish_on_primary = true; + Config config { Session::none(), "NGG", "004", true }; + ILinkGW gw { connection, session, config }; + gw.connect(); + exchange.do_work(); + REQUIRE(gw.state() == State::READY); + REQUIRE(exchange.msg_log == "-> Establish <- EstablishmentReject -> Establish <- EstablishAck -> Sequence <- Sequence "); + } TEST_CASE("MidWeekKeyRotation", "[ilink3][il3cert]") {