In current networks, OSPF ,RIP,etc determine the path taken by a packet. In SDN, the OpenFlow protocol sets the flow tables of the forwarding units. Can someone be very clear that how does OpenFlow decide which path to set for a flow?
Short version: it doesn't.
Longer version: Openflow is just a protocol for communicating between the 'forwarding units' and a controller. It is the controller itself that determines what to do with packets, and it can do this in any way it likes. You can implement most of the current routing protocols in an OpenFlow controller, see for instance RouteFlow.
So the OpenFlow protocol is not used to determine which paths to take, it is just a means of installing the flows in the flow tables. In this sense you can see it as analogous to SNMP and friends (although somewhat more powerful).
As stated by @nik, OpenFlow is just the protocol the controller uses to setup the flows on the network equipment.
As the SDN controller is aware of all packets entering the equipment it controls, it can build a map of ports/mac/ip as devices start to communicate.
There is nothing preventing the controller from running a routing protocol; it could be running OSPF, and have all the devices under it's control look like one huge single router.
- The SDN controller could have any incoming OSPF packet's on the edge forwarded to itself for OSPF processing and respond to them.
- The controller could just switch the OSPF traffic to a actual router, thus the devices under it's control just act's as a big switch.