A CubeSat swarm is comprised of a large number of picoclass, low-power, and low-weight satellite units working together. It brings significant benefits, such as interoperability, reduced mission failure rates, and the ability to perform space communication and observation. However, realizing CubeSat swarms face many challenges, including increased service demands, autonomous operation, relative motion and dynamic routing. Cognitive network in CubeSat swarms has attracted intensive research interest recently and has played a significant role for route selection and resource allocation. In this paper, we consider the cognitive route selection and frequency allocation in a CubeSat swarm based on different network environments and requirements. In a cognitive network, the Master CubeSat can sense the changes about the internal and external environment of the CubeSat swarm, proactively regulates and optimizes the communication network employing the adjustable inter-satellite routing decisions for the CubeSat swarm, improving the capabilities adapted to complex environments and achieve provable energy efficiency. The proposed cognitive algorithm further considers the frequency allocation from millimeter wave to optical wave in the route selection to account for limited bandwidth and restricted data rates. Simulation results and analysis confirm that the proposed route selection and frequency allocation can achieve high energy efficiency improvement and can decrease much time latency as compared to generic route selection approaches.