There is no way to do this with some kind of standard library, but if you want to do this in your own code you can do this:
- Find the nodes where it should connect and insert them into that way. (e.g. node#1234 and node#4321)
- from the placement of those nodes generate a motorway of the correct length in your program
- connect the nodes like this, and add it to the osm file.
<way id=fakeid>
<nd ref="node#1234">
<nd ref="fake node id">
<nd ref="node#4321">
</way>
<node id="fake node id" lat="generate the right length" lon=""/>
But I would probably use JOSM as suggested above like this:
- download the whole area you want to simulate.
- load that into one postgis DB with osm2pgsql.
- start JOSM and draw a line that is roughly the length of the motorway you need, connecting where you want it
- load the changed .osm into another DB
- do you analysis.
Are you sure your program works with Postgis, would be cool to know more. Seems more like you want to develop something like a router, and handling the graphs on your own. e.g. Gosmore could give you time estimations from different points etc..
PS to generate fake ids you can use negative ids, that will work with osm2pgsql.