The Jataka, Vol. II, tr. by W.H.D. Rouse, , at sacred-texts.com
"Foolish Dog," etc. This story the Master told whilst living in Jetavana, about a dog that used to be fed in the resting hall by the Ambala tower.
It is said that from a puppy this dog had been kept there and fed by some water-carriers. In course of time it grew up there to be a big dog. Once a
villager happened to see him; and he bought him from the water-carriers for an upper garment and a rupee; then, fastening him to a chain, led the dog away. The dog was led away, unresisting, making no sound, and followed and followed the new master, eating whatever was offered. "He's fond of me, no doubt," thought the man; and let him free from the chain. No sooner did the dog find himself free, than off he went, and never stopped until he came back to the place he started from.
Seeing him, the Brethren guessed what had happened; and in the evening, when they were gathered in the Hall of Truth, they began talking about it. "Friend--here's the dog back again in our resting hall! how clever he must have been, to get rid of his chain! No sooner free, than back he ran!" The Master, entering, asked what they were all talking about as they sat together. They told him. He rejoined, "Brethren, this is not the first time our dog was clever at getting rid of his chain; he was just the same before." And he told them an old-world tale.
Once upon a time, when Brahmadatta was king of Benares, the Bodhisatta was born in a rich family of the kingdom of Kāsi; and when he grew up, he set up a house of his own. There was a man in Benares who had a dog which had been fed on rice till it grew fat.  And a certain villager who had come to Benares saw the dog; and to the owner he gave a fine garment and a piece of money for the dog, which he led off bound by a strap. Arrived at the outskirts of a forest, he entered a hut, tied up the dog, and lay down to sleep. At that moment the Bodhisatta entered the forest on some errand, and beheld the dog made fast by a thong; whereat he uttered the first stanza:--
On hearing this stanza, the Dog uttered the second:--
So spake he; and when the company were asleep, he gnawed through the strap, and returned to his master's house in great glee.
 When this discourse was ended, the Master identified the Birth:--"The dogs are the same, and I was the wise man."