@Override
    public ObjectNode encode(InstancePort port, CodecContext context) {
        checkNotNull(port, "Instance port cannot be null");

        return context.mapper().createObjectNode()
                .put(NETWORK_ID, port.networkId())
                .put(PORT_ID, port.portId())
                .put(MAC_ADDRESS, port.macAddress().toString())
                .put(IP_ADDRESS, port.ipAddress().toString())
                .put(DEVICE_ID, port.deviceId().toString())
                .put(PORT_NUMBER, port.portNumber().toString())
                .put(STATE, port.state().name());
    }
@Test
    public void testInstancePortEncode() {
        InstancePort port = DefaultInstancePort.builder()
                .networkId("net-id-1")
                .portId("port-id-1")
                .deviceId(DeviceId.deviceId("of:000000000000000a"))
                .portNumber(PortNumber.portNumber(1, "tap-1"))
                .ipAddress(IpAddress.valueOf("10.10.10.1"))
                .macAddress(MacAddress.valueOf("11:22:33:44:55:66"))
                .state(InstancePort.State.valueOf("ACTIVE"))
                .build();

        ObjectNode portJson = instancePortCodec.encode(port, context);
        assertThat(portJson, matchesInstancePort(port));
    }