Secure and stable routing is a critical issue in a conventional network environment, as the control and data planes are integrated. An intelligent routing is highly essential to provide an attack free network to its intended users. The programmable software defined network is an emerging network paradigm in which the security policies and the forwarding rules are implemented in the controller via North Bound Interface. This study incorporates a cognitive neural network learning algorithm namely restricted Boltzmann machine (RBM), to detect the routing-based distributed denial of service attacks in dynamic source routing (DSR) protocol. RBM is a stochastic and unsupervised learning algorithm that self-learns the network conditions by using its reasoning capability and segregates malicious routes in the route cache using context-aware trust metrics such as reputation and energy consumption implemented in North Bound Application Programming Interface. The results show that a cognitive DSR protocol provides secure routing by increased packet delivery ratio, decreased end-to-end delay, reduced energy consumption and accurate detection of malicious routes compared with the conventional DSR protocol.