Skip to main content

cMoflon: Model-Driven Generation of Embedded C Code for Wireless Sensor Networks

Part of the Lecture Notes in Computer Science book series (LNPSE,volume 10376)


Wireless sensor networks (WSNs) are an indispensable part of the emerging Internet of Things. The topology of a WSN is a graph representing the sensor nodes and their interconnecting links. To reduce the energy consumption of a WSN, a topology control algorithm inactivates inessential links, and the sensor nodes reduce their transmission power while preserving crucial integrity properties (e.g., connectivity). In previous work, we have shown that model-driven engineering allows to prototype topology control algorithms that (i) preserve the specified integrity properties and (ii) can be rapidly evaluated in a network simulator. In this paper, we complement our approach by proposing cMoflon, an open-source tool that generates embedded C code for hardware sensor testbeds. The target platform is the Contiki WSN operating system. To show the applicability of cMoflon, we generate code for three representative topology control algorithms: kTC, l*-kTC, and LMST. A comparison of the generated topology control algorithms with their manually tuned counterparts for TelosB sensor nodes shows that cMoflon generates embedded code that is competitive w.r.t. code memory usage.


  • Code generation
  • Wireless sensor networks
  • Model-driven engineering

This is a preview of subscription content, access via your institution.

Buying options

USD   29.95
Price excludes VAT (USA)
  • DOI: 10.1007/978-3-319-61482-3_7
  • Chapter length: 17 pages
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
USD   59.99
Price excludes VAT (USA)
  • ISBN: 978-3-319-61482-3
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
Softcover Book
USD   79.99
Price excludes VAT (USA)
Fig. 1.
Fig. 2.
Fig. 3.
Fig. 4.
Fig. 5.
Fig. 6.


  1. 1.

    cMoflon is open source and available at

  2. 2.

  3. 3.


  4. 4.

    The full source code for all TC algorithms of this paper can be found at

  5. 5.


  6. 6.

    See also

  7. 7.


  1. Al Saad, M., Fehr, E., Kamenzky, N., Schiller, J.: ScatterClipse: a model-driven tool-chain for developing, testing, and prototyping wireless sensor networks. In: Proceedings of the International Symposium on Parallel and Distributed Processing with Applications (ISPA), pp. 871–885 (2008).

  2. Bak, C., Plump, D.: Compiling graph programs to C. In: Echahed, R., Minas, M. (eds.) ICGT 2016. LNCS, vol. 9761, pp. 102–117. Springer, Cham (2016). doi:10.1007/978-3-319-40530-8_7

    CrossRef  Google Scholar 

  3. Berardinelli, L., Di Marco, A., Pace, S., Pomante, L., Tiberti, W.: Energy consumption analysis and design of energy-aware WSN agents in fUML. In: Taentzer, G., Bordeleau, F. (eds.) ECMFA 2015. LNCS, vol. 9153, pp. 1–17. Springer, Cham (2015). doi:10.1007/978-3-319-21151-0_1

    CrossRef  Google Scholar 

  4. Dunkels, A., Gronvall, B., Voigt, T.: Contiki - a lightweight and flexible operating system for tiny networked sensors. In: Proceedings of the International Conference on Local Computer Networks (LCN), pp. 455–462 (2004).

  5. Ehrig, H., Ehrig, K., Prange, U., Taentzer, G.: Fundamentals of Algebraic Graph Transformation. Springer, Heidelberg (2006).

  6. Essaadi, F., Ben Maissa, Y., Dahchour, M.: MDE-based languages for wireless sensor networks modeling: a systematic mapping study. In: El-Azouzi, R., Menasché, D.S., Sabir, E., Pellegrini, F.D., Benjillali, M. (eds.) Advances in Ubiquitous Networking 2. LNEE, vol. 397, pp. 331–346. Springer, Singapore (2017). doi:10.1007/978-981-10-1627-1_26

    CrossRef  Google Scholar 

  7. Fischer, T., Niere, J., Torunski, L., Zündorf, A.: Story diagrams: a new graph rewrite language based on the unified modeling language and java. In: Ehrig, H., Engels, G., Kreowski, H.-J., Rozenberg, G. (eds.) TAGT 1998. LNCS, vol. 1764, pp. 296–309. Springer, Heidelberg (2000). doi:10.1007/978-3-540-46464-8_21

    CrossRef  Google Scholar 

  8. Geiß, R., Batz, G.V., Grund, D., Hack, S., Szalkowski, A.: GrGen: a fast SPO-based graph rewriting tool. In: Corradini, A., Ehrig, H., Montanari, U., Ribeiro, L., Rozenberg, G. (eds.) ICGT 2006. LNCS, vol. 4178, pp. 383–397. Springer, Heidelberg (2006). doi:10.1007/11841883_27

    CrossRef  Google Scholar 

  9. Heckel, R., Wagner, A.: Ensuring consistency of conditional graph rewriting - a constructive approach. In: Proceedings of the Joint COMPUGRAPH/SEMAGRAPH Workshop. ENTCS, vol. 2, pp. 118–126. Elsevier (1995).

  10. Kluge, R., Stein, M., Varró, G., Schürr, A., Hollick, M., Mühlhäuser, M.: A systematic approach to constructing incremental topology control algorithms using graph transformation. J. Vis. Lang. Comput. (JVLC) 38, 47–83 (2016).

    CrossRef  Google Scholar 

  11. Kluge, R., Stein, M., Varró, G., Schürr, A., Hollick, M., Mühlhäuser, M.: A systematic approach to constructing families of incremental topology control algorithms using graph transformation. J. Softw. Syst. Model. (SoSyM), 1–41 (2017).

  12. Kluge, R., Varró, G., Schürr, A.: A methodology for designing dynamic topology control algorithms via graph transformation. In: Kolovos, D., Wimmer, M. (eds.) ICMT 2015. LNCS, vol. 9152, pp. 199–213. Springer, Cham (2015). doi:10.1007/978-3-319-21155-8_15

    CrossRef  Google Scholar 

  13. Leblebici, E., Anjorin, A., Schürr, A.: Developing eMoflon with eMoflon. In: Ruscio, D., Varró, D. (eds.) ICMT 2014. LNCS, vol. 8568, pp. 138–145. Springer, Cham (2014). doi:10.1007/978-3-319-08789-4_10

    Google Scholar 

  14. Li, N., Hou, J.C., Sha, L.: Design and analysis of an MST-based topology control algorithm. IEEE Trans. Wirel. Commun. 4(3), 1195–1206 (2005)

    CrossRef  Google Scholar 

  15. Lim, R., Ferrari, F., Zimmerling, M., Walser, C., Sommer, P., Beutel, J.: FlockLab: a testbed for distributed, synchronized tracing and profiling of wireless embedded systems. In: Proceedings of the ACM/IEEE Conference on Information Processing in Sensor Networks (IPSN), pp. 153–165 (2013).

  16. Polastre, J., Szewczyk, R., Culler, D.: Telos: enabling ultra-low power wireless research. In: International Symposium on Information Processing in Sensor Networks (IPSN), pp. 364–369 (2005).

  17. Portocarrero, J.M.T., Delicato, F.C., Pires, P.F., Rodrigues, T.C., Batista, T.V.: SAMSON: Self-adaptive Middleware for Wireless Sensor Networks. In: Proceedings of the ACM Symposium on Applied Computing (SAC), pp. 1315–1322. ACM, New York (2016).

  18. Richerzhagen, B., Stingl, D., Rückert, J., Steinmetz, R.: Simonstrator: simulation and prototyping platform for distributed mobile applications. In: Proceedings of the International Conference on Simulation Tools and Techniques (SIMUTools), pp. 99–108. ICST (2015).

  19. Rozenberg, G. (ed.): Handbook of Graph Grammars and Computing by Graph Transformation. Foundations, vol. 1. World Scientific (1997).

  20. Santi, P.: Topology Control in Wireless Ad Hoc and Sensor Networks, 1st edn. Wiley, Chichester (2005)

    CrossRef  Google Scholar 

  21. Santi, P.: Topology control in wireless ad hoc and sensor networks. ACM Comput. Surv. (CSUR) 37(2), 164–194 (2005).

    MathSciNet  CrossRef  Google Scholar 

  22. Schweizer, I., Wagner, M., Bradler, D., Mühlhäuser, M., Strufe, T.: kTC - robust and adaptive wireless ad-hoc topology control. In: Proceedings of the International Conference on Computer Communications and Networks (ICCCN), pp. 1–9 (2012).

  23. Stein, M., Petry, T., Schweizer, I., Bachmann, M., Mühlhäuser, M.: Topology control in wireless sensor networks: what blocks the breakthrough? In: Proceedings of the International Conference on Local Computer Networks (LCN), pp. 389–397 (2016).

  24. Steinberg, D., Budinsky, F., Merks, E., Paternostro, M.: EMF: Eclipse Modeling Framework. Addison Wesley Professional, Boston (2008).

    Google Scholar 

  25. Varró, G., Anjorin, A., Schürr, A.: Unification of compiled and interpreter-based pattern matching techniques. In: Vallecillo, A., Tolvanen, J.P., Kindler, E., Störrle, H., Kolovos, D. (eds.) ECMFA 2012. LNCS, vol. 7349, pp. 368–383. Springer, Heidelberg (2012). doi:10.1007/978-3-642-31491-9_28

    CrossRef  Google Scholar 

  26. Völter, M., Stahl, T., Bettin, J., Haase, A., Helsen, S.: Model-Driven Software Development: Technology, Engineering, Management. John Wiley & Sons (2013)

    Google Scholar 

  27. Wang, Y.: Topology control for wireless sensor networks. In: Li, Y., Thai, M.T., Wu, W. (eds.) Wireless Sensor Networks and Applications. Signals and Communication Technology, pp. 113–147. Springer, US (2008). doi:10.1007/978-0-387-49592-7_5

    CrossRef  Google Scholar 

  28. Whitmore, A., Agarwal, A., Da Xu, L.: The internet of things-a survey of topics and trends. Inf. Syst. Front. 17(2), 261–274 (2015).

    CrossRef  Google Scholar 

Download references


This work has been funded by the German Research Foundation (DFG) as part of project A1 within the Collaborative Research Center (CRC) 1053 – MAKI.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Roland Kluge .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and Permissions

Copyright information

© 2017 Springer International Publishing AG

About this paper

Cite this paper

Kluge, R., Stein, M., Giessing, D., Schürr, A., Mühlhäuser, M. (2017). cMoflon: Model-Driven Generation of Embedded C Code for Wireless Sensor Networks. In: Anjorin, A., Espinoza, H. (eds) Modelling Foundations and Applications. ECMFA 2017. Lecture Notes in Computer Science(), vol 10376. Springer, Cham.

Download citation

  • DOI:

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-61481-6

  • Online ISBN: 978-3-319-61482-3

  • eBook Packages: Computer ScienceComputer Science (R0)