The pain that goes with inflammation is cause by distortion of tissues due to edema. The function of inflammation is it neutralize and also destroys toxic agents at the injury site thus restoring tissue homeostasis. During inflammation a chemical mediator called histamine is being released thus would then trigger vasodilation.