@@ -261,25 +261,13 @@ void LinkProber::handleUpdateEthernetFrame()
261
261
//
262
262
void LinkProber::handleSendSwitchCommand ()
263
263
{
264
- resetTxBufferTlv ();
265
- appendTlvCommand (Command::COMMAND_SWITCH_ACTIVE);
266
- appendTlvSentinel ();
267
-
268
- size_t totalPayloadSize = mTxPacketSize - mPacketHeaderSize ;
269
- iphdr *ipHeader = reinterpret_cast <iphdr *> (mTxBuffer .data () + sizeof (ether_header));
270
- icmphdr *icmpHeader = reinterpret_cast <icmphdr *> (mTxBuffer .data () + sizeof (ether_header) + sizeof (iphdr));
271
- computeChecksum (icmpHeader, sizeof (icmphdr) + totalPayloadSize);
272
- ipHeader->tot_len = htons (sizeof (iphdr) + sizeof (icmphdr) + totalPayloadSize);
264
+ initTxBufferTlvSendSwitch ();
273
265
274
266
sendHeartbeat ();
275
267
276
- resetTxBufferTlv ();
277
- appendTlvSentinel ();
278
- totalPayloadSize = mTxPacketSize - mPacketHeaderSize ;
279
- computeChecksum (icmpHeader, sizeof (icmphdr) + totalPayloadSize);
280
- ipHeader->tot_len = htons (sizeof (iphdr) + sizeof (icmphdr) + totalPayloadSize);
268
+ initTxBufferTlvSentinel ();
281
269
282
- // inform the composite state machine about commend send completion
270
+ // inform the composite state machine about command send completion
283
271
boost::asio::io_service::strand &strand = mLinkProberStateMachinePtr ->getStrand ();
284
272
boost::asio::io_service &ioService = strand.context ();
285
273
ioService.post (strand.wrap (boost::bind (
@@ -754,6 +742,48 @@ size_t LinkProber::appendTlvDummy(size_t paddingSize, int seqNo)
754
742
return tlvSize;
755
743
}
756
744
745
+ //
746
+ // ---> initTxBufferTlvSendSwitch
747
+ //
748
+ // Initialize TX buffer TLVs to send switch command to peer
749
+ //
750
+ void LinkProber::initTxBufferTlvSendSwitch ()
751
+ {
752
+ resetTxBufferTlv ();
753
+ appendTlvCommand (Command::COMMAND_SWITCH_ACTIVE);
754
+ appendTlvSentinel ();
755
+
756
+ calculateTxPacketChecksum ();
757
+ }
758
+
759
+ //
760
+ // ---> initTxBufferTlvSentinel
761
+ //
762
+ // Initialize TX buffer to have only TLV sentinel
763
+ //
764
+ void LinkProber::initTxBufferTlvSentinel ()
765
+ {
766
+ resetTxBufferTlv ();
767
+ appendTlvSentinel ();
768
+
769
+ calculateTxPacketChecksum ();
770
+ }
771
+
772
+ //
773
+ // ---> calculateChecksum
774
+ //
775
+ // Calculate TX packet checksums in both IP header and ICMP header
776
+ //
777
+ void LinkProber::calculateTxPacketChecksum ()
778
+ {
779
+ size_t totalPayloadSize = mTxPacketSize - mPacketHeaderSize ;
780
+ iphdr *ipHeader = reinterpret_cast <iphdr *> (mTxBuffer .data () + sizeof (ether_header));
781
+ icmphdr *icmpHeader = reinterpret_cast <icmphdr *> (mTxBuffer .data () + sizeof (ether_header) + sizeof (iphdr));
782
+ computeChecksum (icmpHeader, sizeof (icmphdr) + totalPayloadSize);
783
+ ipHeader->tot_len = htons (sizeof (iphdr) + sizeof (icmphdr) + totalPayloadSize);
784
+ computeChecksum (ipHeader, ipHeader->ihl << 2 );
785
+ }
786
+
757
787
//
758
788
// ---> resetIcmpPacketCounts
759
789
//
0 commit comments