To do it yourself you need to line up your outbound SIP providers, inbound DID providers (not one and the same once you dig into the details), then you need to operate a bunch of Freeswitch / Asterisk / whatever SIP servers, and learn how to program them, and learn how keep them running smooth (Not particularly difficult, but in terms of learning requirements - it's akin to meeting a database + web server for the first time).
Due to the real-time nature of telcos (and I mean that in the traditional clock-synch'd sense of the word) there are additional complications if you want to use a virtualised OS.