The advanced metering infrastructure (AMI) is one of the main services of smart grid (SG), which collects data from smart meters (SMs) and sends them to utility company meter data management systems (MDMSs) via a communication network. In the next generation AMI, both the number of SMs and the meter sampling frequency will dramatically increase, thus creating a huge traffic load which should be efficiently routed and balanced across the communication network and MDMSs. This paper initially formulates the global load-balanced routing problem in the AMI communication network as an integer linear programming model, which is NP-hard. Then, to overcome this drawback, it is decomposed into two subproblems and a novel software defined network-based AMI communication network is proposed called OpenAMI. This paper also extends the OpenAMI for the cloud computing environment in which some virtual MDMSs are available. OpenAMI is implemented on a real test bed, which includes Open vSwitch, Floodlight controller, and OpenStack, and its performance is evaluated by extensive experiments and scenarios. Based on the results, OpenAMI achieves low end-to-end delay and a high delivery ratio by balancing the load on the entire AMI network.