Mobile ad hoc network is a network composed of mobile terminals without infrastructure. Due to its fast-networking ability, it is widely used in smart cities, car networking, military, agriculture, medicine, and other fields. Routing technology is a key technology in the field of MANET (mobile ad hoc network). The energy consumption is optimized through the technical network simulator NS-3, and the nodes in the MANET routing protocol can accurately simulate the problem, thereby optimizing the MAC layer of important research tools. This article combines the advantages of the lithium-ion (lithium) battery model. Compared with the KiBaM battery model, the effective charge in the KiBaM model simulates the output voltage well, which can reflect the battery capacity effect rate and the recovery effect of the lithium-ion-KiBaM battery model. The model can respond to the characteristics of the output voltage as the society gets lower and lower. In order to solve the problem that the analytic solution of differential equations cannot be obtained in the model, a numerical solution of the optimization algorithm is proposed based on the implicit Runge–Kutta method. The MAC layer energy consumption and routing protocol optimization algorithm proposed in this paper can be applied well in various fields.